VirtualBox

Changeset 66502 in vbox


Ignore:
Timestamp:
Apr 10, 2017 3:27:38 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Machine settings: Serial page: Error handling (settings save).

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r66501 r66502  
    5959# include "CAudioAdapter.h"
    6060# include "CParallelPort.h"
     61# include "CSerialPort.h"
    6162# include "CConsole.h"
    6263# include "CMachine.h"
     
    12351236    error(pParent, MessageType_Error,
    12361237          tr("Cannot save parallel port settings."),
     1238          formatErrorInfo(comPort));
     1239}
     1240
     1241void UIMessageCenter::cannotSaveSerialSettings(const CMachine &comMachine, QWidget *pParent /* = 0 */)
     1242{
     1243    error(pParent, MessageType_Error,
     1244          tr("Cannot save serial ports settings."),
     1245          formatErrorInfo(comMachine));
     1246}
     1247
     1248void UIMessageCenter::cannotSaveSerialPortSettings(const CSerialPort &comPort, QWidget *pParent /* = 0 */)
     1249{
     1250    error(pParent, MessageType_Error,
     1251          tr("Cannot save serial port settings."),
    12371252          formatErrorInfo(comPort));
    12381253}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r66501 r66502  
    251251    void cannotSaveParallelSettings(const CMachine &comMachine, QWidget *pParent = 0);
    252252    void cannotSaveParallelPortSettings(const CParallelPort &comPort, QWidget *pParent = 0);
     253    void cannotSaveSerialSettings(const CMachine &comMachine, QWidget *pParent = 0);
     254    void cannotSaveSerialPortSettings(const CSerialPort &comPort, QWidget *pParent = 0);
    253255    void cannotAttachDevice(const CMachine &machine, UIMediumType type, const QString &strLocation, const StorageSlot &storageSlot, QWidget *pParent = 0);
    254256    bool warnAboutIncorrectPort(QWidget *pParent = 0) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.cpp

    r66460 r66502  
    2828# include "UIConverter.h"
    2929# include "UIMachineSettingsSerial.h"
     30# include "UIMessageCenter.h"
    3031# include "VBoxGlobal.h"
    3132
     
    459460    UISettingsPageMachine::fetchData(data);
    460461
    461     /* Make sure machine is offline & serial data was changed: */
    462     if (isMachineOffline() && m_pCache->wasChanged())
    463     {
    464         /* For each serial port: */
    465         for (int iPort = 0; iPort < m_pTabWidget->count(); ++iPort)
    466         {
    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)
    474             {
    475                 /* Check if port still valid: */
    476                 CSerialPort comPort = m_machine.GetSerialPort(iPort);
    477                 /* Store new adapter data: */
    478                 if (!comPort.isNull())
    479                 {
    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);
    506                 }
    507             }
    508         }
    509     }
     462    /* Update serial data and failing state: */
     463    setFailed(!saveSerialData());
    510464
    511465    /* Upload machine to data: */
     
    656610}
    657611
     612bool UIMachineSettingsSerialPage::saveSerialData()
     613{
     614    /* Prepare result: */
     615    bool fSuccess = true;
     616    /* Save serial settings from the cache: */
     617    if (fSuccess && isMachineInValidMode() && m_pCache->wasChanged())
     618    {
     619        /* For each port: */
     620        for (int iSlot = 0; fSuccess && iSlot < m_pTabWidget->count(); ++iSlot)
     621            fSuccess = savePortData(iSlot);
     622    }
     623    /* Return result: */
     624    return fSuccess;
     625}
     626
     627bool UIMachineSettingsSerialPage::savePortData(int iPort)
     628{
     629    /* Prepare result: */
     630    bool fSuccess = true;
     631    /* Save adapter settings from the cache: */
     632    if (fSuccess)
     633    {
     634        /* Get old serial data from the cache: */
     635        const UIDataSettingsMachineSerialPort &oldPortData = m_pCache->base().m_ports.at(iPort);
     636        /* Get new serial data from the cache: */
     637        const UIDataSettingsMachineSerialPort &newPortData = m_pCache->data().m_ports.at(iPort);
     638
     639        /* Make sure port data was changed: */
     640        if (newPortData != oldPortData)
     641        {
     642            /* Get serial port for further activities: */
     643            CSerialPort comPort = m_machine.GetSerialPort(iPort);
     644            fSuccess = m_machine.isOk() && comPort.isNotNull();
     645            /* Show error message if necessary: */
     646            if (!fSuccess)
     647                msgCenter().cannotSaveSerialSettings(m_machine, this);
     648
     649            // This *must* be first.
     650            // If the requested host mode is changed to disconnected we should do it first.
     651            // That allows to automatically fulfill the requirements for some of the settings below.
     652            /* Save port host mode: */
     653            if (   fSuccess && isMachineOffline()
     654                && newPortData.m_hostMode != oldPortData.m_hostMode
     655                && newPortData.m_hostMode == KPortMode_Disconnected)
     656            {
     657                comPort.SetHostMode(newPortData.m_hostMode);
     658                fSuccess = comPort.isOk();
     659            }
     660            /* Save whether the port is enabled: */
     661            if (fSuccess && isMachineOffline() && newPortData.m_fPortEnabled != oldPortData.m_fPortEnabled)
     662            {
     663                comPort.SetEnabled(newPortData.m_fPortEnabled);
     664                fSuccess = comPort.isOk();
     665            }
     666            /* Save port IRQ: */
     667            if (fSuccess && isMachineOffline() && newPortData.m_uIRQ != oldPortData.m_uIRQ)
     668            {
     669                comPort.SetIRQ(newPortData.m_uIRQ);
     670                fSuccess = comPort.isOk();
     671            }
     672            /* Save port IO base: */
     673            if (fSuccess && isMachineOffline() && newPortData.m_uIOBase != oldPortData.m_uIOBase)
     674            {
     675                comPort.SetIOBase(newPortData.m_uIOBase);
     676                fSuccess = comPort.isOk();
     677            }
     678            /* Save whether the port is server: */
     679            if (fSuccess && isMachineOffline() && newPortData.m_fServer != oldPortData.m_fServer)
     680            {
     681                comPort.SetServer(newPortData.m_fServer);
     682                fSuccess = comPort.isOk();
     683            }
     684            /* Save port path: */
     685            if (fSuccess && isMachineOffline() && newPortData.m_strPath != oldPortData.m_strPath)
     686            {
     687                comPort.SetPath(newPortData.m_strPath);
     688                fSuccess = comPort.isOk();
     689            }
     690            // This *must* be last.
     691            // The host mode will be changed to disconnected if some of the necessary
     692            // settings above will not meet the requirements for the selected mode.
     693            /* Save port host mode: */
     694            if (   fSuccess && isMachineOffline()
     695                && newPortData.m_hostMode != oldPortData.m_hostMode
     696                && newPortData.m_hostMode != KPortMode_Disconnected)
     697            {
     698                comPort.SetHostMode(newPortData.m_hostMode);
     699                fSuccess = comPort.isOk();
     700            }
     701            /* Show error message if necessary: */
     702            if (!fSuccess)
     703                msgCenter().cannotSaveSerialPortSettings(comPort, this);
     704        }
     705    }
     706    /* Return result: */
     707    return fSuccess;
     708}
     709
    658710# include "UIMachineSettingsSerial.moc"
    659711
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSerial.h

    r66366 r66502  
    7777    void cleanup();
    7878
     79    /** Saves existing serial data from the cache. */
     80    bool saveSerialData();
     81    /** Saves existing port data from the cache. */
     82    bool savePortData(int iPort);
     83
    7984    /** Holds the tab-widget instance. */
    8085    QITabWidget *m_pTabWidget;
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