Changeset 90223 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jul 16, 2021 8:49:52 AM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/wizards
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.cpp
r90217 r90223 19 19 #include <QButtonGroup> 20 20 #include <QCheckBox> 21 #include <QDir> 22 #include <QFileInfo> 21 23 #include <QLabel> 22 24 #include <QRadioButton> … … 66 68 } 67 69 70 const CMediumFormat &UIDiskFormatsGroupBox::VDIMeiumFormat() const 71 { 72 return m_comVDIMediumFormat; 73 } 74 68 75 void UIDiskFormatsGroupBox::prepare() 69 76 { … … 78 85 foreach (const CMediumFormat &format, formats) 79 86 { 80 /* VDI goes first: */81 87 if (format.GetName() == "VDI") 88 { 82 89 vdi[format.GetId()] = format; 90 m_comVDIMediumFormat = format; 91 } 83 92 else 84 93 { 85 94 const QVector<KMediumFormatCapabilities> &capabilities = format.GetCapabilities(); 86 /* Then goes preferred: */87 95 if (capabilities.contains(KMediumFormatCapabilities_Preferred)) 88 96 preferred[format.GetId()] = format; 89 /* Then others: */90 97 else 91 98 others[format.GetId()] = format; … … 165 172 } 166 173 174 /* static */ 167 175 QString UIDiskFormatsGroupBox::defaultExtension(const CMediumFormat &mediumFormatRef) 168 176 { … … 182 190 } 183 191 192 const QStringList UIDiskFormatsGroupBox::formatExtensions() const 193 { 194 return m_formatExtensions; 195 } 196 184 197 /********************************************************************************************************************************* 185 198 * UIDiskVariantGroupBox implementation. * … … 220 233 } 221 234 235 qulonglong UIDiskVariantGroupBox::mediumVariant() const 236 { 237 /* Initial value: */ 238 qulonglong uMediumVariant = (qulonglong)KMediumVariant_Max; 239 240 /* Exclusive options: */ 241 if (m_pFixedCheckBox && m_pFixedCheckBox->isChecked()) 242 uMediumVariant = (qulonglong)KMediumVariant_Fixed; 243 else 244 uMediumVariant = (qulonglong)KMediumVariant_Standard; 245 246 /* Additional options: */ 247 if (m_pSplitBox && m_pSplitBox->isChecked()) 248 uMediumVariant |= (qulonglong)KMediumVariant_VmdkSplit2G; 249 250 /* Return options: */ 251 return uMediumVariant; 252 } 253 254 void UIDiskVariantGroupBox::setMediumVariant(qulonglong uMediumVariant) 255 { 256 /* Exclusive options: */ 257 if (uMediumVariant & (qulonglong)KMediumVariant_Fixed) 258 { 259 m_pFixedCheckBox->click(); 260 m_pFixedCheckBox->setFocus(); 261 } 262 263 /* Additional options: */ 264 m_pSplitBox->setChecked(uMediumVariant & (qulonglong)KMediumVariant_VmdkSplit2G); 265 } 266 267 void UIDiskVariantGroupBox::setWidgetVisibility(CMediumFormat &mediumFormat) 268 { 269 ULONG uCapabilities = 0; 270 QVector<KMediumFormatCapabilities> capabilities; 271 capabilities = mediumFormat.GetCapabilities(); 272 for (int i = 0; i < capabilities.size(); i++) 273 uCapabilities |= capabilities[i]; 274 275 bool fIsCreateDynamicPossible = uCapabilities & KMediumFormatCapabilities_CreateDynamic; 276 bool fIsCreateFixedPossible = uCapabilities & KMediumFormatCapabilities_CreateFixed; 277 bool fIsCreateSplitPossible = uCapabilities & KMediumFormatCapabilities_CreateSplit2G; 278 if (m_pFixedCheckBox) 279 { 280 if (!fIsCreateDynamicPossible) 281 { 282 m_pFixedCheckBox->setChecked(true); 283 m_pFixedCheckBox->setEnabled(false); 284 } 285 if (!fIsCreateFixedPossible) 286 { 287 m_pFixedCheckBox->setChecked(false); 288 m_pFixedCheckBox->setEnabled(false); 289 } 290 } 291 if (m_pFixedCheckBox) 292 m_pFixedCheckBox->setHidden(!fIsCreateFixedPossible); 293 if (m_pSplitBox) 294 m_pSplitBox->setHidden(!fIsCreateSplitPossible); 295 } 296 297 void UIDiskVariantGroupBox::updateMediumVariantWidgetsAfterFormatChange(const CMediumFormat &mediumFormat) 298 { 299 /* Enable/disable widgets: */ 300 ULONG uCapabilities = 0; 301 QVector<KMediumFormatCapabilities> capabilities; 302 capabilities = mediumFormat.GetCapabilities(); 303 for (int i = 0; i < capabilities.size(); i++) 304 uCapabilities |= capabilities[i]; 305 306 bool fIsCreateDynamicPossible = uCapabilities & KMediumFormatCapabilities_CreateDynamic; 307 bool fIsCreateFixedPossible = uCapabilities & KMediumFormatCapabilities_CreateFixed; 308 bool fIsCreateSplitPossible = uCapabilities & KMediumFormatCapabilities_CreateSplit2G; 309 310 if (m_pFixedCheckBox) 311 { 312 m_pFixedCheckBox->setEnabled(fIsCreateDynamicPossible || fIsCreateFixedPossible); 313 if (!fIsCreateDynamicPossible) 314 m_pFixedCheckBox->setChecked(true); 315 if (!fIsCreateFixedPossible) 316 m_pFixedCheckBox->setChecked(false); 317 } 318 m_pSplitBox->setEnabled(fIsCreateSplitPossible); 319 } 320 321 bool UIDiskVariantGroupBox::isComplete() const 322 { 323 /* Make sure medium variant is correct: */ 324 return mediumVariant() != (qulonglong)KMediumVariant_Max; 325 } 326 222 327 223 328 /********************************************************************************************************************************* … … 286 391 m_pLocationEditor->setText(strLocation); 287 392 } 393 394 void UIDiskSizeAndLocationGroupBox::updateLocationEditorAfterFormatChange(const CMediumFormat &mediumFormat, const QStringList &formatExtensions) 395 { 396 /* Compose virtual-disk extension: */ 397 QString strDefaultExtension = UIDiskFormatsGroupBox::defaultExtension(mediumFormat); 398 /* Update m_pLocationEditor's text if necessary: */ 399 if (!m_pLocationEditor->text().isEmpty() && !strDefaultExtension.isEmpty()) 400 { 401 QFileInfo fileInfo(m_pLocationEditor->text()); 402 if (fileInfo.suffix() != strDefaultExtension) 403 { 404 QFileInfo newFileInfo(QDir(fileInfo.absolutePath()), 405 QString("%1.%2"). 406 arg(stripFormatExtension(fileInfo.fileName(), formatExtensions)). 407 arg(strDefaultExtension)); 408 m_pLocationEditor->setText(newFileInfo.absoluteFilePath()); 409 } 410 } 411 } 412 413 /* static */ 414 QString UIDiskSizeAndLocationGroupBox::stripFormatExtension(const QString &strFileName, const QStringList &formatExtensions) 415 { 416 QString result(strFileName); 417 foreach (const QString &strExtension, formatExtensions) 418 { 419 if (strFileName.endsWith(strExtension, Qt::CaseInsensitive)) 420 { 421 /* Add the dot to extenstion: */ 422 QString strExtensionWithDot(strExtension); 423 strExtensionWithDot.prepend('.'); 424 int iIndex = strFileName.lastIndexOf(strExtensionWithDot, -1, Qt::CaseInsensitive); 425 result.remove(iIndex, strExtensionWithDot.length()); 426 } 427 } 428 return result; 429 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.h
r90217 r90223 61 61 CMediumFormat mediumFormat() const; 62 62 void setMediumFormat(const CMediumFormat &mediumFormat); 63 const CMediumFormat &VDIMeiumFormat() const; 64 static QString defaultExtension(const CMediumFormat &mediumFormatRef); 65 const QStringList formatExtensions() const; 63 66 64 67 private: … … 66 69 void prepare(); 67 70 void addFormatButton(QVBoxLayout *pFormatLayout, CMediumFormat medFormat, bool fPreferred = false); 68 QString defaultExtension(const CMediumFormat &mediumFormatRef); 71 69 72 virtual void retranslateUi() /* override final */; 70 73 71 74 QList<CMediumFormat> m_formats; 75 CMediumFormat m_comVDIMediumFormat; 72 76 QStringList m_formatNames; 73 77 QStringList m_formatExtensions; … … 85 89 86 90 UIDiskVariantGroupBox(QWidget *pParent = 0); 91 void updateMediumVariantWidgetsAfterFormatChange(const CMediumFormat &mediumFormat); 92 qulonglong mediumVariant() const; 93 void setMediumVariant(qulonglong uMediumVariant); 94 void setWidgetVisibility(CMediumFormat &mediumFormat); 95 bool isComplete() const; 87 96 88 97 private: … … 110 119 QString location() const; 111 120 void setLocation(const QString &strLocation); 121 void updateLocationEditorAfterFormatChange(const CMediumFormat &mediumFormat, const QStringList &formatExtensions); 112 122 113 123 private: … … 115 125 void prepare(); 116 126 virtual void retranslateUi() /* override final */; 127 static QString stripFormatExtension(const QString &strFileName, 128 const QStringList &formatExtensions); 129 117 130 118 131 QLabel *m_pLocationLabel; -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMNameOSTypePageBasic.cpp
r90101 r90223 179 179 }; 180 180 181 void UIWizardNewVMNameOSTypePage:: onNameChanged(UINameAndSystemEditor *pNameAndSystemEditor, QString strNewName)181 void UIWizardNewVMNameOSTypePage::guessOSTypeFromName(UINameAndSystemEditor *pNameAndSystemEditor, QString strNewName) 182 182 { 183 183 CHost host = uiCommon().host(); … … 366 366 void UIWizardNewVMNameOSTypePageBasic::sltNameChanged(const QString &strNewName) 367 367 { 368 UIWizardNewVMNameOSTypePage::onNameChanged(m_pNameAndSystemEditor, strNewName); 368 if (!m_userModifiedParameters.contains("GuestOSType")) 369 UIWizardNewVMNameOSTypePage::guessOSTypeFromName(m_pNameAndSystemEditor, strNewName); 369 370 UIWizardNewVMNameOSTypePage::composeMachineFilePath(m_pNameAndSystemEditor, qobject_cast<UIWizardNewVM*>(wizard())); 370 371 emit completeChanged(); … … 379 380 void UIWizardNewVMNameOSTypePageBasic::sltOsTypeChanged() 380 381 { 381 /* If the user manually edited the OS type, we didn't want our automatic OS type guessing anymore. 382 * So simply disconnect the text-edit signal. */ 382 m_userModifiedParameters << "GuestOSType"; 383 383 if (m_pNameAndSystemEditor) 384 {385 m_pNameAndSystemEditor->disconnect(SIGNAL(sigNameChanged(const QString &)), this, SLOT(sltNameChanged(const QString &)));386 384 newVMWizardPropertySet(GuestOSType, m_pNameAndSystemEditor->type()); 387 }388 385 } 389 386 … … 453 450 if (pWizard) 454 451 { 455 if (!pWizard->detectedOSTypeId().isEmpty() )456 UIWizardNewVMNameOSTypePage:: onNameChanged(m_pNameAndSystemEditor, pWizard->detectedOSTypeId());452 if (!pWizard->detectedOSTypeId().isEmpty() && !m_userModifiedParameters.contains("GuestOSType")) 453 UIWizardNewVMNameOSTypePage::guessOSTypeFromName(m_pNameAndSystemEditor, pWizard->detectedOSTypeId()); 457 454 pWizard->setISOFilePath(strPath); 458 455 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMNameOSTypePageBasic.h
r90095 r90223 40 40 namespace UIWizardNewVMNameOSTypePage 41 41 { 42 void onNameChanged(UINameAndSystemEditor *pNameAndSystemEditor, QString strNewName);42 void guessOSTypeFromName(UINameAndSystemEditor *pNameAndSystemEditor, QString strNewName); 43 43 bool createMachineFolder(UINameAndSystemEditor *pNameAndSystemEditor, 44 44 UINativeWizardPage *pCaller, … … 104 104 QIRichTextLabel *m_pNameOSTypeLabel; 105 105 /** @} */ 106 QSet<QString> m_userModifiedParameters; 106 107 }; 107 108 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp
r90217 r90223 120 120 void UIWizardNewVMPageExpert::sltNameChanged(const QString &strNewName) 121 121 { 122 UIWizardNewVMNameOSTypePage::onNameChanged(m_pNameAndSystemEditor, strNewName); 122 if (!m_userModifiedParameters.contains("GuestOSType")) 123 UIWizardNewVMNameOSTypePage::guessOSTypeFromName(m_pNameAndSystemEditor, strNewName); 123 124 UIWizardNewVMNameOSTypePage::composeMachineFilePath(m_pNameAndSystemEditor, qobject_cast<UIWizardNewVM*>(wizard())); 124 125 updateVirtualDiskPathFromMachinePathName(); … … 135 136 void UIWizardNewVMPageExpert::sltOsTypeChanged() 136 137 { 137 // onOsTypeChanged(); 138 // setOSTypeDependedValues(); 139 // emit completeChanged(); 138 m_userModifiedParameters << "GuestOSType"; 139 if (m_pNameAndSystemEditor) 140 newVMWizardPropertySet(GuestOSType, m_pNameAndSystemEditor->type()); 141 //setOSTypeDependedValues() ??!!! 140 142 } 141 143 … … 216 218 connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigNameChanged, 217 219 this, &UIWizardNewVMPageExpert::sltNameChanged); 218 //connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigPathChanged,219 //this, &UIWizardNewVMPageExpert::sltPathChanged);220 //connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOsTypeChanged,221 //this, &UIWizardNewVMPageExpert::sltOsTypeChanged);220 connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigPathChanged, 221 this, &UIWizardNewVMPageExpert::sltPathChanged); 222 connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOsTypeChanged, 223 this, &UIWizardNewVMPageExpert::sltOsTypeChanged); 222 224 // connect(m_pNameAndSystemEditor, &UINameAndSystemEditor::sigOSFamilyChanged, 223 225 // this, &UIWizardNewVMPageExpert::sltOSFamilyTypeChanged); … … 277 279 void UIWizardNewVMPageExpert::setOSTypeDependedValues() 278 280 { 279 // if (!field("type").canConvert<CGuestOSType>()) 280 // return; 281 282 // /* Get recommended 'ram' field value: */ 283 // CGuestOSType type = field("type").value<CGuestOSType>(); 284 // ULONG recommendedRam = type.GetRecommendedRAM(); 285 286 // if (m_pBaseMemoryEditor && !m_userSetWidgets.contains(m_pBaseMemoryEditor)) 287 // { 288 // m_pBaseMemoryEditor->blockSignals(true); 289 // m_pBaseMemoryEditor->setValue(recommendedRam); 290 // m_pBaseMemoryEditor->blockSignals(false); 291 // } 281 UIWizardNewVM *pWizard = qobject_cast<UIWizardNewVM*>(wizard()); 282 AssertReturnVoid(pWizard); 283 284 /* Get recommended 'ram' field value: */ 285 const CGuestOSType &type = pWizard->guestOSType(); 286 ULONG recommendedRam = type.GetRecommendedRAM(); 287 288 /* Set memory size of the widget and (through signals) wizard: */ 289 if (m_pHardwareWidgetContainer && !m_userModifiedParameters.contains("MemorySize")) 290 m_pHardwareWidgetContainer->setMemorySize(recommendedRam); 291 292 292 293 293 // KFirmwareType fwType = type.GetRecommendedFirmware(); … … 342 342 AssertReturnVoid(pWizard); 343 343 /* Initialize wizard properties: */ 344 if (m_pNameAndSystemEditor) 345 { 346 /* Guest OS type: */ 347 newVMWizardPropertySet(GuestOSFamilyId, m_pNameAndSystemEditor->familyId()); 348 newVMWizardPropertySet(GuestOSType, m_pNameAndSystemEditor->type()); 349 /* Vm name, folder, file path etc. will be initilized by composeMachineFilePath: */ 350 } 351 352 344 353 if (m_pFormatButtonGroup) 345 354 newVMWizardPropertySet(MediumFormat, m_pFormatButtonGroup->mediumFormat()); … … 347 356 348 357 // disableEnableUnattendedRelatedWidgets(isUnattendedEnabled()); 349 //setOSTypeDependedValues();358 setOSTypeDependedValues(); 350 359 // disableEnableUnattendedRelatedWidgets(isUnattendedEnabled()); 351 360 updateVirtualDiskPathFromMachinePathName(); 361 352 362 // updateWidgetAterMediumFormatChange(); 353 363 // setSkipCheckBoxEnable(); … … 669 679 void UIWizardNewVMPageExpert::updateWidgetAterMediumFormatChange() 670 680 { 671 // CMediumFormat comMediumFormat = mediumFormat(); 672 // if (comMediumFormat.isNull()) 673 // { 674 // AssertMsgFailed(("No medium format set!")); 675 // return; 676 // } 677 // updateMediumVariantWidgetsAfterFormatChange(comMediumFormat); 678 // updateLocationEditorAfterFormatChange(comMediumFormat, m_formatExtensions); 681 UIWizardNewVM *pWizard = qobject_cast<UIWizardNewVM*>(wizard()); 682 AssertReturnVoid(pWizard && m_pDiskVariantGroupBox && m_pSizeAndLocationGroup && m_pFormatButtonGroup); 683 const CMediumFormat &comMediumFormat = pWizard->mediumFormat(); 684 AssertReturnVoid(!comMediumFormat.isNull()); 685 m_pDiskVariantGroupBox->updateMediumVariantWidgetsAfterFormatChange(comMediumFormat); 686 m_pSizeAndLocationGroup->updateLocationEditorAfterFormatChange(comMediumFormat, m_pFormatButtonGroup->formatExtensions()); 679 687 } 680 688
Note:
See TracChangeset
for help on using the changeset viewer.