Changeset 66436 in vbox
- Timestamp:
- Apr 5, 2017 1:20:29 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsGeneral.cpp
r66345 r66436 178 178 m_pCache->clear(); 179 179 180 /* Prepare general data: */181 UIDataSettingsMachineGeneral generalData;182 183 /* 'Basic' tabdata: */184 generalData.m_strName = m_machine.GetName();185 generalData.m_strGuestOsTypeId = m_machine.GetOSTypeId();186 187 /* 'Advanced' tabdata: */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' tabdata: */194 generalData.m_strDescription = m_machine.GetDescription();195 196 /* 'Encryption' tabdata: */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: */ 197 197 QString strCipher; 198 198 bool fEncryptionCipherCommon = true; … … 201 201 foreach (const CMediumAttachment &attachment, m_machine.GetMediumAttachments()) 202 202 { 203 /* Acquirehard-drive attachments only: */203 /* Check hard-drive attachments only: */ 204 204 if (attachment.GetType() == KDeviceType_HardDisk) 205 205 { 206 206 /* Get the attachment medium base: */ 207 const CMedium medium = attachment.GetMedium();207 const CMedium comMedium = attachment.GetMedium(); 208 208 /* Check medium encryption attributes: */ 209 209 QString strCurrentCipher; 210 const QString strCurrentPasswordId = medium.GetEncryptionSettings(strCurrentCipher);211 if ( medium.isOk())210 const QString strCurrentPasswordId = comMedium.GetEncryptionSettings(strCurrentCipher); 211 if (comMedium.isOk()) 212 212 { 213 encryptedMediums.insert(strCurrentPasswordId, medium.GetId());213 encryptedMediums.insert(strCurrentPasswordId, comMedium.GetId()); 214 214 if (strCurrentCipher != strCipher) 215 215 { … … 222 222 } 223 223 } 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; 227 227 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); 235 235 236 236 /* Upload machine to data: */ … … 240 240 void UIMachineSettingsGeneral::getFromCache() 241 241 { 242 /* Get general data fromcache: */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: */ 246 246 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: */ 251 251 AssertPtrReturnVoid(mPsSnapshot); 252 252 AssertPtrReturnVoid(mCbClipboard); 253 253 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: */ 260 260 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: */ 264 264 AssertPtrReturnVoid(m_pCheckBoxEncryption); 265 265 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; 270 270 271 271 /* Polish page finally: */ … … 278 278 void UIMachineSettingsGeneral::putToCache() 279 279 { 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: */ 284 284 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: */ 289 289 AssertPtrReturnVoid(mPsSnapshot); 290 290 AssertPtrReturnVoid(mCbClipboard); 291 291 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: */ 297 297 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: */ 302 302 AssertPtrReturnVoid(m_pCheckBoxEncryption); 303 303 AssertPtrReturnVoid(m_pComboCipher); 304 304 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(); 310 310 /* 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) 314 314 { 315 315 /* Ask for the disk encryption passwords if necessary: */ … … 320 320 QPointer<UIAddDiskEncryptionPasswordDialog> pDlg = 321 321 new UIAddDiskEncryptionPasswordDialog(pDlgParent, 322 generalData.m_strName,323 generalData.m_encryptedMediums);322 newGeneralData.m_strName, 323 newGeneralData.m_encryptedMediums); 324 324 /* Execute it and acquire the result: */ 325 325 if (pDlg->exec() == QDialog::Accepted) 326 generalData.m_encryptionPasswords = pDlg->encryptionPasswords();326 newGeneralData.m_encryptionPasswords = pDlg->encryptionPasswords(); 327 327 /* Delete dialog if still valid: */ 328 328 if (pDlg) … … 331 331 } 332 332 333 /* Cache general data: */334 m_pCache->cacheCurrentData( generalData);333 /* Cache new general data: */ 334 m_pCache->cacheCurrentData(newGeneralData); 335 335 } 336 336 … … 340 340 UISettingsPageMachine::fetchData(data); 341 341 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); 360 379 361 380 if (isMachineOffline()) 362 381 { 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, 385 383 * or the encryption was already enabled and either cipher or password is changed. */ 386 if ( generalData.m_fEncryptionEnabled != m_pCache->base().m_fEncryptionEnabled387 || ( m_pCache->base().m_fEncryptionEnabled388 && ( generalData.m_fEncryptionCipherChanged != m_pCache->base().m_fEncryptionCipherChanged389 || 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))) 390 388 { 391 389 /* Cipher attribute changed? */ 392 390 QString strNewCipher; 393 if ( generalData.m_fEncryptionCipherChanged)391 if (newGeneralData.m_fEncryptionCipherChanged) 394 392 { 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(); 397 395 } 398 396 /* Password attribute changed? */ 399 397 QString strNewPassword; 400 398 QString strNewPasswordId; 401 if ( generalData.m_fEncryptionPasswordChanged)399 if (newGeneralData.m_fEncryptionPasswordChanged) 402 400 { 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 ? 406 404 m_machine.GetName() : QString(); 407 405 } 408 406 409 407 /* 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; 412 410 /* Enumerate attachments: */ 413 411 foreach (const CMediumAttachment &attachment, m_machine.GetMediumAttachments()) … … 417 415 { 418 416 /* Get corresponding medium: */ 419 CMedium medium = attachment.GetMedium();417 CMedium comMedium = attachment.GetMedium(); 420 418 421 419 /* 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); 424 422 425 423 /* 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()) 431 429 { 432 430 QMetaObject::invokeMethod(this, "sigOperationProgressError", Qt::BlockingQueuedConnection, 433 Q_ARG(QString, UIMessageCenter::formatErrorInfo( medium)));431 Q_ARG(QString, UIMessageCenter::formatErrorInfo(comMedium))); 434 432 continue; 435 433 }
Note:
See TracChangeset
for help on using the changeset viewer.