VirtualBox

Changeset 66436 in vbox


Ignore:
Timestamp:
Apr 5, 2017 1:20:29 PM (8 years ago)
Author:
vboxsync
Message:

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

File:
1 edited

Legend:

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

    r66345 r66436  
    178178    m_pCache->clear();
    179179
    180     /* Prepare general data: */
    181     UIDataSettingsMachineGeneral generalData;
    182 
    183     /* 'Basic' tab data: */
    184     generalData.m_strName = m_machine.GetName();
    185     generalData.m_strGuestOsTypeId = m_machine.GetOSTypeId();
    186 
    187     /* 'Advanced' tab data: */
    188     generalData.m_strSnapshotsFolder = m_machine.GetSnapshotFolder();
    189     generalData.m_strSnapshotsHomeDir = QFileInfo(m_machine.GetSettingsFilePath()).absolutePath();
    190     generalData.m_clipboardMode = m_machine.GetClipboardMode();
    191     generalData.m_dndMode = m_machine.GetDnDMode();
    192 
    193     /* 'Description' tab data: */
    194     generalData.m_strDescription = m_machine.GetDescription();
    195 
    196     /* 'Encryption' tab data: */
     180    /* Prepare old general data: */
     181    UIDataSettingsMachineGeneral oldGeneralData;
     182
     183    /* Gather old 'Basic' data: */
     184    oldGeneralData.m_strName = m_machine.GetName();
     185    oldGeneralData.m_strGuestOsTypeId = m_machine.GetOSTypeId();
     186
     187    /* Gather old 'Advanced' data: */
     188    oldGeneralData.m_strSnapshotsFolder = m_machine.GetSnapshotFolder();
     189    oldGeneralData.m_strSnapshotsHomeDir = QFileInfo(m_machine.GetSettingsFilePath()).absolutePath();
     190    oldGeneralData.m_clipboardMode = m_machine.GetClipboardMode();
     191    oldGeneralData.m_dndMode = m_machine.GetDnDMode();
     192
     193    /* Gather old 'Description' data: */
     194    oldGeneralData.m_strDescription = m_machine.GetDescription();
     195
     196    /* Gather old 'Encryption' data: */
    197197    QString strCipher;
    198198    bool fEncryptionCipherCommon = true;
     
    201201    foreach (const CMediumAttachment &attachment, m_machine.GetMediumAttachments())
    202202    {
    203         /* Acquire hard-drive attachments only: */
     203        /* Check hard-drive attachments only: */
    204204        if (attachment.GetType() == KDeviceType_HardDisk)
    205205        {
    206206            /* Get the attachment medium base: */
    207             const CMedium medium = attachment.GetMedium();
     207            const CMedium comMedium = attachment.GetMedium();
    208208            /* Check medium encryption attributes: */
    209209            QString strCurrentCipher;
    210             const QString strCurrentPasswordId = medium.GetEncryptionSettings(strCurrentCipher);
    211             if (medium.isOk())
     210            const QString strCurrentPasswordId = comMedium.GetEncryptionSettings(strCurrentCipher);
     211            if (comMedium.isOk())
    212212            {
    213                 encryptedMediums.insert(strCurrentPasswordId, medium.GetId());
     213                encryptedMediums.insert(strCurrentPasswordId, comMedium.GetId());
    214214                if (strCurrentCipher != strCipher)
    215215                {
     
    222222        }
    223223    }
    224     generalData.m_fEncryptionEnabled = !encryptedMediums.isEmpty();
    225     generalData.m_fEncryptionCipherChanged = false;
    226     generalData.m_fEncryptionPasswordChanged = false;
     224    oldGeneralData.m_fEncryptionEnabled = !encryptedMediums.isEmpty();
     225    oldGeneralData.m_fEncryptionCipherChanged = false;
     226    oldGeneralData.m_fEncryptionPasswordChanged = false;
    227227    if (fEncryptionCipherCommon)
    228         generalData.m_iEncryptionCipherIndex = m_encryptionCiphers.indexOf(strCipher);
    229     if (generalData.m_iEncryptionCipherIndex == -1)
    230         generalData.m_iEncryptionCipherIndex = 0;
    231     generalData.m_encryptedMediums = encryptedMediums;
    232 
    233     /* Cache general data: */
    234     m_pCache->cacheInitialData(generalData);
     228        oldGeneralData.m_iEncryptionCipherIndex = m_encryptionCiphers.indexOf(strCipher);
     229    if (oldGeneralData.m_iEncryptionCipherIndex == -1)
     230        oldGeneralData.m_iEncryptionCipherIndex = 0;
     231    oldGeneralData.m_encryptedMediums = encryptedMediums;
     232
     233    /* Cache old general data: */
     234    m_pCache->cacheInitialData(oldGeneralData);
    235235
    236236    /* Upload machine to data: */
     
    240240void UIMachineSettingsGeneral::getFromCache()
    241241{
    242     /* Get general data from cache: */
    243     const UIDataSettingsMachineGeneral &generalData = m_pCache->base();
    244 
    245     /* 'Basic' tab data: */
     242    /* Get old general data from the cache: */
     243    const UIDataSettingsMachineGeneral &oldGeneralData = m_pCache->base();
     244
     245    /* Load old 'Basic' data to the page: */
    246246    AssertPtrReturnVoid(m_pNameAndSystemEditor);
    247     m_pNameAndSystemEditor->setName(generalData.m_strName);
    248     m_pNameAndSystemEditor->setType(vboxGlobal().vmGuestOSType(generalData.m_strGuestOsTypeId));
    249 
    250     /* 'Advanced' tab data: */
     247    m_pNameAndSystemEditor->setName(oldGeneralData.m_strName);
     248    m_pNameAndSystemEditor->setType(vboxGlobal().vmGuestOSType(oldGeneralData.m_strGuestOsTypeId));
     249
     250    /* Load old 'Advanced' data to the page: */
    251251    AssertPtrReturnVoid(mPsSnapshot);
    252252    AssertPtrReturnVoid(mCbClipboard);
    253253    AssertPtrReturnVoid(mCbDragAndDrop);
    254     mPsSnapshot->setPath(generalData.m_strSnapshotsFolder);
    255     mPsSnapshot->setHomeDir(generalData.m_strSnapshotsHomeDir);
    256     mCbClipboard->setCurrentIndex(generalData.m_clipboardMode);
    257     mCbDragAndDrop->setCurrentIndex(generalData.m_dndMode);
    258 
    259     /* 'Description' tab data: */
     254    mPsSnapshot->setPath(oldGeneralData.m_strSnapshotsFolder);
     255    mPsSnapshot->setHomeDir(oldGeneralData.m_strSnapshotsHomeDir);
     256    mCbClipboard->setCurrentIndex(oldGeneralData.m_clipboardMode);
     257    mCbDragAndDrop->setCurrentIndex(oldGeneralData.m_dndMode);
     258
     259    /* Load old 'Description' data to the page: */
    260260    AssertPtrReturnVoid(mTeDescription);
    261     mTeDescription->setPlainText(generalData.m_strDescription);
    262 
    263     /* 'Encryption' tab data: */
     261    mTeDescription->setPlainText(oldGeneralData.m_strDescription);
     262
     263    /* Load old 'Encryption' data to the page: */
    264264    AssertPtrReturnVoid(m_pCheckBoxEncryption);
    265265    AssertPtrReturnVoid(m_pComboCipher);
    266     m_pCheckBoxEncryption->setChecked(generalData.m_fEncryptionEnabled);
    267     m_pComboCipher->setCurrentIndex(generalData.m_iEncryptionCipherIndex);
    268     m_fEncryptionCipherChanged = generalData.m_fEncryptionCipherChanged;
    269     m_fEncryptionPasswordChanged = generalData.m_fEncryptionPasswordChanged;
     266    m_pCheckBoxEncryption->setChecked(oldGeneralData.m_fEncryptionEnabled);
     267    m_pComboCipher->setCurrentIndex(oldGeneralData.m_iEncryptionCipherIndex);
     268    m_fEncryptionCipherChanged = oldGeneralData.m_fEncryptionCipherChanged;
     269    m_fEncryptionPasswordChanged = oldGeneralData.m_fEncryptionPasswordChanged;
    270270
    271271    /* Polish page finally: */
     
    278278void UIMachineSettingsGeneral::putToCache()
    279279{
    280     /* Prepare general data: */
    281     UIDataSettingsMachineGeneral generalData = m_pCache->base();
    282 
    283     /* 'Basic' tab data: */
     280    /* Prepare new general data: */
     281    UIDataSettingsMachineGeneral newGeneralData;
     282
     283    /* Gather new 'Basic' data from page: */
    284284    AssertPtrReturnVoid(m_pNameAndSystemEditor);
    285     generalData.m_strName = m_pNameAndSystemEditor->name();
    286     generalData.m_strGuestOsTypeId = m_pNameAndSystemEditor->type().GetId();
    287 
    288     /* 'Advanced' tab data: */
     285    newGeneralData.m_strName = m_pNameAndSystemEditor->name();
     286    newGeneralData.m_strGuestOsTypeId = m_pNameAndSystemEditor->type().GetId();
     287
     288    /* Gather new 'Advanced' data from page: */
    289289    AssertPtrReturnVoid(mPsSnapshot);
    290290    AssertPtrReturnVoid(mCbClipboard);
    291291    AssertPtrReturnVoid(mCbDragAndDrop);
    292     generalData.m_strSnapshotsFolder = mPsSnapshot->path();
    293     generalData.m_clipboardMode = (KClipboardMode)mCbClipboard->currentIndex();
    294     generalData.m_dndMode = (KDnDMode)mCbDragAndDrop->currentIndex();
    295 
    296     /* 'Description' tab data: */
     292    newGeneralData.m_strSnapshotsFolder = mPsSnapshot->path();
     293    newGeneralData.m_clipboardMode = (KClipboardMode)mCbClipboard->currentIndex();
     294    newGeneralData.m_dndMode = (KDnDMode)mCbDragAndDrop->currentIndex();
     295
     296    /* Gather new 'Description' data from page: */
    297297    AssertPtrReturnVoid(mTeDescription);
    298     generalData.m_strDescription = mTeDescription->toPlainText().isEmpty() ?
    299                                    QString::null : mTeDescription->toPlainText();
    300 
    301     /* 'Encryption' tab data: */
     298    newGeneralData.m_strDescription = mTeDescription->toPlainText().isEmpty() ?
     299                                      QString::null : mTeDescription->toPlainText();
     300
     301    /* Gather new 'Encryption' data from page: */
    302302    AssertPtrReturnVoid(m_pCheckBoxEncryption);
    303303    AssertPtrReturnVoid(m_pComboCipher);
    304304    AssertPtrReturnVoid(m_pEditorEncryptionPassword);
    305     generalData.m_fEncryptionEnabled = m_pCheckBoxEncryption->isChecked();
    306     generalData.m_fEncryptionCipherChanged = m_fEncryptionCipherChanged;
    307     generalData.m_fEncryptionPasswordChanged = m_fEncryptionPasswordChanged;
    308     generalData.m_iEncryptionCipherIndex = m_pComboCipher->currentIndex();
    309     generalData.m_strEncryptionPassword = m_pEditorEncryptionPassword->text();
     305    newGeneralData.m_fEncryptionEnabled = m_pCheckBoxEncryption->isChecked();
     306    newGeneralData.m_fEncryptionCipherChanged = m_fEncryptionCipherChanged;
     307    newGeneralData.m_fEncryptionPasswordChanged = m_fEncryptionPasswordChanged;
     308    newGeneralData.m_iEncryptionCipherIndex = m_pComboCipher->currentIndex();
     309    newGeneralData.m_strEncryptionPassword = m_pEditorEncryptionPassword->text();
    310310    /* If encryption status, cipher or password is changed: */
    311     if (generalData.m_fEncryptionEnabled != m_pCache->base().m_fEncryptionEnabled ||
    312         generalData.m_fEncryptionCipherChanged != m_pCache->base().m_fEncryptionCipherChanged ||
    313         generalData.m_fEncryptionPasswordChanged != m_pCache->base().m_fEncryptionPasswordChanged)
     311    if (newGeneralData.m_fEncryptionEnabled != m_pCache->base().m_fEncryptionEnabled ||
     312        newGeneralData.m_fEncryptionCipherChanged != m_pCache->base().m_fEncryptionCipherChanged ||
     313        newGeneralData.m_fEncryptionPasswordChanged != m_pCache->base().m_fEncryptionPasswordChanged)
    314314    {
    315315        /* Ask for the disk encryption passwords if necessary: */
     
    320320            QPointer<UIAddDiskEncryptionPasswordDialog> pDlg =
    321321                 new UIAddDiskEncryptionPasswordDialog(pDlgParent,
    322                                                        generalData.m_strName,
    323                                                        generalData.m_encryptedMediums);
     322                                                       newGeneralData.m_strName,
     323                                                       newGeneralData.m_encryptedMediums);
    324324            /* Execute it and acquire the result: */
    325325            if (pDlg->exec() == QDialog::Accepted)
    326                 generalData.m_encryptionPasswords = pDlg->encryptionPasswords();
     326                newGeneralData.m_encryptionPasswords = pDlg->encryptionPasswords();
    327327            /* Delete dialog if still valid: */
    328328            if (pDlg)
     
    331331    }
    332332
    333     /* Cache general data: */
    334     m_pCache->cacheCurrentData(generalData);
     333    /* Cache new general data: */
     334    m_pCache->cacheCurrentData(newGeneralData);
    335335}
    336336
     
    340340    UISettingsPageMachine::fetchData(data);
    341341
    342     /* Check if general data was changed: */
    343     if (m_pCache->wasChanged())
    344     {
    345         /* Get general data from cache: */
    346         const UIDataSettingsMachineGeneral &generalData = m_pCache->data();
    347 
    348         if (isMachineInValidMode())
    349         {
    350             /* 'Advanced' tab data: */
    351             if (generalData.m_clipboardMode != m_pCache->base().m_clipboardMode)
    352                 m_machine.SetClipboardMode(generalData.m_clipboardMode);
    353             if (generalData.m_dndMode != m_pCache->base().m_dndMode)
    354                 m_machine.SetDnDMode(generalData.m_dndMode);
    355 
    356             /* 'Description' tab: */
    357             if (generalData.m_strDescription != m_pCache->base().m_strDescription)
    358                 m_machine.SetDescription(generalData.m_strDescription);
    359         }
     342    /* Make sure machine is in valid mode & general data was changed: */
     343    if (isMachineInValidMode() && m_pCache->wasChanged())
     344    {
     345        /* Get old general data from the cache: */
     346        const UIDataSettingsMachineGeneral &oldGeneralData = m_pCache->base();
     347        /* Get new general data from the cache: */
     348        const UIDataSettingsMachineGeneral &newGeneralData = m_pCache->data();
     349
     350        /* Store machine OS type ID: */
     351        if (isMachineOffline() && newGeneralData.m_strGuestOsTypeId != oldGeneralData.m_strGuestOsTypeId)
     352        {
     353            m_machine.SetOSTypeId(newGeneralData.m_strGuestOsTypeId);
     354            // Must update long mode CPU feature bit when os type changed:
     355            CVirtualBox vbox = vboxGlobal().virtualBox();
     356            const CGuestOSType enmNewType = vbox.GetGuestOSType(newGeneralData.m_strGuestOsTypeId);
     357            m_machine.SetCPUProperty(KCPUPropertyType_LongMode, enmNewType.GetIs64Bit());
     358        }
     359
     360        /* Store machine clipboard mode: */
     361        if (newGeneralData.m_clipboardMode != oldGeneralData.m_clipboardMode)
     362            m_machine.SetClipboardMode(newGeneralData.m_clipboardMode);
     363        /* Store machine D&D mode: */
     364        if (newGeneralData.m_dndMode != oldGeneralData.m_dndMode)
     365            m_machine.SetDnDMode(newGeneralData.m_dndMode);
     366        /* Store machine snapshot folder: */
     367        if (isMachineOffline() && newGeneralData.m_strSnapshotsFolder != oldGeneralData.m_strSnapshotsFolder)
     368            m_machine.SetSnapshotFolder(newGeneralData.m_strSnapshotsFolder);
     369
     370        // VM name should go after the snapshot folder from the 'Advanced' data
     371        // as otherwise VM rename magic can collide with the snapshot folder one.
     372        /* Store machine name: */
     373        if (isMachineOffline() && newGeneralData.m_strName != oldGeneralData.m_strName)
     374            m_machine.SetName(newGeneralData.m_strName);
     375
     376        /* Store machine description: */
     377        if (newGeneralData.m_strDescription != oldGeneralData.m_strDescription)
     378            m_machine.SetDescription(newGeneralData.m_strDescription);
    360379
    361380        if (isMachineOffline())
    362381        {
    363             /* 'Basic' tab data: Must update long mode CPU feature bit when os type changes. */
    364             if (generalData.m_strGuestOsTypeId != m_pCache->base().m_strGuestOsTypeId)
    365             {
    366                 m_machine.SetOSTypeId(generalData.m_strGuestOsTypeId);
    367                 CVirtualBox vbox = vboxGlobal().virtualBox();
    368                 CGuestOSType newType = vbox.GetGuestOSType(generalData.m_strGuestOsTypeId);
    369                 m_machine.SetCPUProperty(KCPUPropertyType_LongMode, newType.GetIs64Bit());
    370             }
    371 
    372             /* 'Advanced' tab data: */
    373             if (generalData.m_strSnapshotsFolder != m_pCache->base().m_strSnapshotsFolder)
    374                 m_machine.SetSnapshotFolder(generalData.m_strSnapshotsFolder);
    375 
    376             /* 'Basic' (again) tab data: */
    377             /* VM name must be last as otherwise its VM rename magic
    378              * can collide with other settings in the config,
    379              * especially with the snapshot folder: */
    380             if (generalData.m_strName != m_pCache->base().m_strName)
    381                 m_machine.SetName(generalData.m_strName);
    382 
    383             /* Encryption tab data:
    384              * Make sure it either encryption is changed itself,
     382            /* Make sure it either encryption is changed itself,
    385383             * or the encryption was already enabled and either cipher or password is changed. */
    386             if (   generalData.m_fEncryptionEnabled != m_pCache->base().m_fEncryptionEnabled
    387                 || (   m_pCache->base().m_fEncryptionEnabled
    388                     && (   generalData.m_fEncryptionCipherChanged != m_pCache->base().m_fEncryptionCipherChanged
    389                         || generalData.m_fEncryptionPasswordChanged != m_pCache->base().m_fEncryptionPasswordChanged)))
     384            if (   newGeneralData.m_fEncryptionEnabled != oldGeneralData.m_fEncryptionEnabled
     385                || (   oldGeneralData.m_fEncryptionEnabled
     386                    && (   newGeneralData.m_fEncryptionCipherChanged != oldGeneralData.m_fEncryptionCipherChanged
     387                        || newGeneralData.m_fEncryptionPasswordChanged != oldGeneralData.m_fEncryptionPasswordChanged)))
    390388            {
    391389                /* Cipher attribute changed? */
    392390                QString strNewCipher;
    393                 if (generalData.m_fEncryptionCipherChanged)
     391                if (newGeneralData.m_fEncryptionCipherChanged)
    394392                {
    395                     strNewCipher = generalData.m_fEncryptionEnabled ?
    396                                    m_encryptionCiphers.at(generalData.m_iEncryptionCipherIndex) : QString();
     393                    strNewCipher = newGeneralData.m_fEncryptionEnabled ?
     394                                   m_encryptionCiphers.at(newGeneralData.m_iEncryptionCipherIndex) : QString();
    397395                }
    398396                /* Password attribute changed? */
    399397                QString strNewPassword;
    400398                QString strNewPasswordId;
    401                 if (generalData.m_fEncryptionPasswordChanged)
     399                if (newGeneralData.m_fEncryptionPasswordChanged)
    402400                {
    403                     strNewPassword = generalData.m_fEncryptionEnabled ?
    404                                      generalData.m_strEncryptionPassword : QString();
    405                     strNewPasswordId = generalData.m_fEncryptionEnabled ?
     401                    strNewPassword = newGeneralData.m_fEncryptionEnabled ?
     402                                     newGeneralData.m_strEncryptionPassword : QString();
     403                    strNewPasswordId = newGeneralData.m_fEncryptionEnabled ?
    406404                                       m_machine.GetName() : QString();
    407405                }
    408406
    409407                /* Get the maps of encrypted mediums and their passwords: */
    410                 const EncryptedMediumMap &encryptedMedium = generalData.m_encryptedMediums;
    411                 const EncryptionPasswordMap &encryptionPasswords = generalData.m_encryptionPasswords;
     408                const EncryptedMediumMap &encryptedMedium = newGeneralData.m_encryptedMediums;
     409                const EncryptionPasswordMap &encryptionPasswords = newGeneralData.m_encryptionPasswords;
    412410                /* Enumerate attachments: */
    413411                foreach (const CMediumAttachment &attachment, m_machine.GetMediumAttachments())
     
    417415                    {
    418416                        /* Get corresponding medium: */
    419                         CMedium medium = attachment.GetMedium();
     417                        CMedium comMedium = attachment.GetMedium();
    420418
    421419                        /* Check if old password exists/provided: */
    422                         QString strOldPasswordId = encryptedMedium.key(medium.GetId());
    423                         QString strOldPassword = encryptionPasswords.value(strOldPasswordId);
     420                        const QString strOldPasswordId = encryptedMedium.key(comMedium.GetId());
     421                        const QString strOldPassword = encryptionPasswords.value(strOldPasswordId);
    424422
    425423                        /* Update encryption: */
    426                         CProgress cprogress = medium.ChangeEncryption(strOldPassword,
    427                                                                       strNewCipher,
    428                                                                       strNewPassword,
    429                                                                       strNewPasswordId);
    430                         if (!medium.isOk())
     424                        CProgress cprogress = comMedium.ChangeEncryption(strOldPassword,
     425                                                                         strNewCipher,
     426                                                                         strNewPassword,
     427                                                                         strNewPasswordId);
     428                        if (!comMedium.isOk())
    431429                        {
    432430                            QMetaObject::invokeMethod(this, "sigOperationProgressError", Qt::BlockingQueuedConnection,
    433                                                       Q_ARG(QString, UIMessageCenter::formatErrorInfo(medium)));
     431                                                      Q_ARG(QString, UIMessageCenter::formatErrorInfo(comMedium)));
    434432                            continue;
    435433                        }
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