VirtualBox

Changeset 66442 in vbox


Ignore:
Timestamp:
Apr 5, 2017 2:17:49 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114413
Message:

FE/Qt: Machine settings: Serial Port page: Proper loading, caching, saving (2nd iteration, s.a. r114309).

File:
1 edited

Legend:

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

    r66375 r66442  
    365365    m_pCache->clear();
    366366
    367     /* Prepare initial data: */
    368     UIDataSettingsMachineSerial initialData;
    369 
    370     /* For each serial port: */
     367    /* Prepare old parallel data: */
     368    UIDataSettingsMachineSerial oldSerialData;
     369
     370    /* For each port: */
    371371    for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
    372372    {
    373         /* Prepare port data: */
    374         UIDataSettingsMachineSerialPort initialPortData;
    375 
    376         /* Check if port is valid: */
    377         const CSerialPort &port = m_machine.GetSerialPort(iSlot);
    378         if (!port.isNull())
     373        /* Prepare old port data: */
     374        UIDataSettingsMachineSerialPort oldPortData;
     375
     376        /* Check whether port is valid: */
     377        const CSerialPort &comPort = m_machine.GetSerialPort(iSlot);
     378        if (!comPort.isNull())
    379379        {
    380             /* Gather options: */
    381             initialPortData.m_iSlot = iSlot;
    382             initialPortData.m_fPortEnabled = port.GetEnabled();
    383             initialPortData.m_uIRQ = port.GetIRQ();
    384             initialPortData.m_uIOBase = port.GetIOBase();
    385             initialPortData.m_hostMode = port.GetHostMode();
    386             initialPortData.m_fServer = port.GetServer();
    387             initialPortData.m_strPath = port.GetPath();
     380            /* Gather old port data: */
     381            oldPortData.m_iSlot = iSlot;
     382            oldPortData.m_fPortEnabled = comPort.GetEnabled();
     383            oldPortData.m_uIRQ = comPort.GetIRQ();
     384            oldPortData.m_uIOBase = comPort.GetIOBase();
     385            oldPortData.m_hostMode = comPort.GetHostMode();
     386            oldPortData.m_fServer = comPort.GetServer();
     387            oldPortData.m_strPath = comPort.GetPath();
    388388        }
    389389
    390         /* Append initial port data: */
    391         initialData.m_ports << initialPortData;
    392     }
    393 
    394     /* Cache initial data: */
    395     m_pCache->cacheInitialData(initialData);
     390        /* Cache old port data: */
     391        oldSerialData.m_ports << oldPortData;
     392    }
     393
     394    /* Cache old serial data: */
     395    m_pCache->cacheInitialData(oldSerialData);
    396396
    397397    /* Upload machine to data: */
     
    406406    QWidget *pLastFocusWidget = m_pTabWidget->focusProxy();
    407407
    408     /* For each serial port: */
     408    /* For each port: */
    409409    for (int iPort = 0; iPort < m_pTabWidget->count(); ++iPort)
    410410    {
     
    412412        UIMachineSettingsSerial *pPage = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iPort));
    413413
    414         /* Load port data to page: */
     414        /* Load old port data to the page: */
    415415        pPage->loadPortData(m_pCache->base().m_ports.at(iPort));
    416416
     
    431431void UIMachineSettingsSerialPage::putToCache()
    432432{
    433     /* Prepare current data: */
    434     UIDataSettingsMachineSerial currentData;
    435 
    436     /* For each serial port: */
     433    /* Prepare new serial data: */
     434    UIDataSettingsMachineSerial newSerialData;
     435
     436    /* For each port: */
    437437    for (int iPort = 0; iPort < m_pTabWidget->count(); ++iPort)
    438438    {
     
    440440        UIMachineSettingsSerial *pTab = qobject_cast<UIMachineSettingsSerial*>(m_pTabWidget->widget(iPort));
    441441
    442         /* Prepare current port data: */
    443         UIDataSettingsMachineSerialPort currentPortData;
    444 
    445         /* Gather current port data: */
    446         pTab->savePortData(currentPortData);
    447 
    448         /* Cache current port data: */
    449         currentData.m_ports << currentPortData;
    450     }
    451 
    452     /* Cache current data: */
    453     m_pCache->cacheCurrentData(currentData);
     442        /* Prepare new port data: */
     443        UIDataSettingsMachineSerialPort newPortData;
     444
     445        /* Gather new port data: */
     446        pTab->savePortData(newPortData);
     447
     448        /* Cache new port data: */
     449        newSerialData.m_ports << newPortData;
     450    }
     451
     452    /* Cache new serial data: */
     453    m_pCache->cacheCurrentData(newSerialData);
    454454}
    455455
     
    459459    UISettingsPageMachine::fetchData(data);
    460460
    461     /* Check if ports data was changed: */
    462     if (m_pCache->wasChanged())
     461    /* Make sure machine is offline & serial data was changed: */
     462    if (isMachineOffline() && m_pCache->wasChanged())
    463463    {
    464464        /* For each serial port: */
    465465        for (int iPort = 0; iPort < m_pTabWidget->count(); ++iPort)
    466466        {
    467             /* Check if port data was changed: */
    468             const UIDataSettingsMachineSerialPort &initialPortData = m_pCache->base().m_ports.at(iPort);
    469             const UIDataSettingsMachineSerialPort &currentPortData = m_pCache->data().m_ports.at(iPort);
    470             if (currentPortData != initialPortData)
     467            /* Get old serial data from the cache: */
     468            const UIDataSettingsMachineSerialPort &oldPortData = m_pCache->base().m_ports.at(iPort);
     469            /* Get new serial data from the cache: */
     470            const UIDataSettingsMachineSerialPort &newPortData = m_pCache->data().m_ports.at(iPort);
     471
     472            /* Make sure port data was changed: */
     473            if (newPortData != oldPortData)
    471474            {
    472475                /* Check if port still valid: */
    473                 CSerialPort port = m_machine.GetSerialPort(iPort);
    474                 if (!port.isNull())
     476                CSerialPort comPort = m_machine.GetSerialPort(iPort);
     477                /* Store new adapter data: */
     478                if (!comPort.isNull())
    475479                {
    476                     /* Store adapter data: */
    477                     if (isMachineOffline())
    478                     {
    479                         /* Whether the port is enabled: */
    480                         if (   port.isOk()
    481                             && currentPortData.m_fPortEnabled != initialPortData.m_fPortEnabled)
    482                             port.SetEnabled(currentPortData.m_fPortEnabled);
    483                         /* Port IRQ: */
    484                         if (   port.isOk()
    485                             && currentPortData.m_uIRQ != initialPortData.m_uIRQ)
    486                             port.SetIRQ(currentPortData.m_uIRQ);
    487                         /* Port IO base: */
    488                         if (   port.isOk()
    489                             && currentPortData.m_uIOBase != initialPortData.m_uIOBase)
    490                             port.SetIOBase(currentPortData.m_uIOBase);
    491                         /* Whether the port is server: */
    492                         if (   port.isOk()
    493                             && currentPortData.m_fServer != initialPortData.m_fServer)
    494                             port.SetServer(currentPortData.m_fServer);
    495                         /* Port path: */
    496                         if (   port.isOk()
    497                             && currentPortData.m_strPath != initialPortData.m_strPath)
    498                             port.SetPath(currentPortData.m_strPath);
    499                         /* This *must* be last. The host mode will be changed to disconnected if
    500                          * some of the necessary settings above will not meet the requirements for
    501                          * the selected mode. */
    502                         if (   port.isOk()
    503                             && currentPortData.m_hostMode != initialPortData.m_hostMode)
    504                             port.SetHostMode(currentPortData.m_hostMode);
    505                     }
     480                    /* Whether the port is enabled: */
     481                    if (   comPort.isOk()
     482                        && newPortData.m_fPortEnabled != oldPortData.m_fPortEnabled)
     483                        comPort.SetEnabled(newPortData.m_fPortEnabled);
     484                    /* Port IRQ: */
     485                    if (   comPort.isOk()
     486                        && newPortData.m_uIRQ != oldPortData.m_uIRQ)
     487                        comPort.SetIRQ(newPortData.m_uIRQ);
     488                    /* Port IO base: */
     489                    if (   comPort.isOk()
     490                        && newPortData.m_uIOBase != oldPortData.m_uIOBase)
     491                        comPort.SetIOBase(newPortData.m_uIOBase);
     492                    /* Whether the port is server: */
     493                    if (   comPort.isOk()
     494                        && newPortData.m_fServer != oldPortData.m_fServer)
     495                        comPort.SetServer(newPortData.m_fServer);
     496                    /* Port path: */
     497                    if (   comPort.isOk()
     498                        && newPortData.m_strPath != oldPortData.m_strPath)
     499                        comPort.SetPath(newPortData.m_strPath);
     500                    /* This *must* be last. The host mode will be changed to disconnected if
     501                     * some of the necessary settings above will not meet the requirements for
     502                     * the selected mode. */
     503                    if (   comPort.isOk()
     504                        && newPortData.m_hostMode != oldPortData.m_hostMode)
     505                        comPort.SetHostMode(newPortData.m_hostMode);
    506506                }
    507507            }
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