- Timestamp:
- Jul 29, 2021 9:40:13 AM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/wizards
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.cpp
r90370 r90400 57 57 } 58 58 59 /* static */ 60 QString UIDiskEditorGroupBox::appendExtension(const QString &strName, const QString &strExtension) 61 { 62 /* Convert passed name to native separators: */ 63 QString strFileName = QDir::toNativeSeparators(strName); 64 65 /* Remove all trailing dots to avoid multiple dots before extension: */ 66 int iLen; 67 while (iLen = strFileName.length(), iLen > 0 && strFileName[iLen - 1] == '.') 68 strFileName.truncate(iLen - 1); 69 70 /* Add passed extension if its not done yet: */ 71 if (QFileInfo(strFileName).suffix().toLower() != strExtension) 72 strFileName += QString(".%1").arg(strExtension); 73 74 /* Return result: */ 75 return strFileName; 76 } 77 78 /* static */ 79 QString UIDiskEditorGroupBox::constructMediumFilePath(const QString &strFileName, const QString &strPath) 80 { 81 /* Wrap file-info around received file name: */ 82 QFileInfo fileInfo(strFileName); 83 /* If path-info is relative or there is no path-info at all: */ 84 if (fileInfo.fileName() == strFileName || fileInfo.isRelative()) 85 { 86 /* Resolve path on the basis of path we have: */ 87 fileInfo = QFileInfo(strPath, strFileName); 88 } 89 /* Return full absolute hard disk file path: */ 90 return QDir::toNativeSeparators(fileInfo.absoluteFilePath()); 91 } 92 93 /* static */ 94 QString UIDiskEditorGroupBox::defaultExtensionForMediumFormat(const CMediumFormat &mediumFormatRef) 95 { 96 if (!mediumFormatRef.isNull()) 97 { 98 /* Load extension / device list: */ 99 QVector<QString> fileExtensions; 100 QVector<KDeviceType> deviceTypes; 101 CMediumFormat mediumFormat(mediumFormatRef); 102 mediumFormat.DescribeFileExtensions(fileExtensions, deviceTypes); 103 for (int i = 0; i < fileExtensions.size(); ++i) 104 if (deviceTypes[i] == KDeviceType_HardDisk) 105 return fileExtensions[i].toLower(); 106 } 107 AssertMsgFailed(("Extension can't be NULL!\n")); 108 return QString(); 109 } 110 111 59 112 /********************************************************************************************************************************* 60 113 * UIDiskFormatsGroupBox implementation. * -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardDiskEditors.h
r90370 r90400 57 57 58 58 UIDiskEditorGroupBox(bool fExpertMode, QWidget *pParent = 0); 59 60 static QString appendExtension(const QString &strName, const QString &strExtension); 61 static QString constructMediumFilePath(const QString &strFileName, const QString &strPath); 62 static QString defaultExtensionForMediumFormat(const CMediumFormat &mediumFormatRef); 59 63 60 64 protected: -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageSizeLocation.cpp
r90362 r90400 279 279 // } 280 280 281 UIWizardNewVDPageSizeLocation::UIWizardNewVDPageSizeLocation(const QString &/*strDefaultName*/, const QString &/*strDefaultPath*/, qulonglong /*uDefaultSize*/) 281 UIWizardNewVDPageSizeLocation::UIWizardNewVDPageSizeLocation(const QString &strDefaultName, 282 const QString &strDefaultPath, qulonglong uDefaultSize) 282 283 : m_pMediumSizePathGroup(0) 284 , m_uMediumSizeMin(_4M) 285 , m_uMediumSizeMax(uiCommon().virtualBox().GetSystemProperties().GetInfoVDSize()) 286 , m_strDefaultName(strDefaultName.isEmpty() ? QString("NewVirtualDisk1") : strDefaultName) 287 , m_strDefaultPath(strDefaultPath) 288 , m_uDefaultSize(uDefaultSize) 283 289 { 284 290 … … 300 306 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 301 307 AssertReturnVoid(pMainLayout); 302 m_pMediumSizePathGroup = new UIMediumSizeAndPathGroupBox(false , 0);308 m_pMediumSizePathGroup = new UIMediumSizeAndPathGroupBox(false /* fExpertMode */, 0); 303 309 // { 304 310 // m_pLocationLabel = new QIRichTextLabel(this); … … 320 326 // pMainLayout->addLayout(pLocationLayout); 321 327 // pMainLayout->addWidget(m_pSizeLabel); 328 connect(m_pMediumSizePathGroup, &UIMediumSizeAndPathGroupBox::sigMediumSizeChanged, 329 this, &UIWizardNewVDPageSizeLocation::sltMediumSizeChanged); 330 connect(m_pMediumSizePathGroup, &UIMediumSizeAndPathGroupBox::sigMediumPathChanged, 331 this, &UIWizardNewVDPageSizeLocation::sltMediumPathChanged); 332 connect(m_pMediumSizePathGroup, &UIMediumSizeAndPathGroupBox::sigMediumLocationButtonClicked, 333 this, &UIWizardNewVDPageSizeLocation::sltSelectLocationButtonClicked); 322 334 pMainLayout->addWidget(m_pMediumSizePathGroup); 323 335 pMainLayout->addStretch(); … … 332 344 } 333 345 346 void UIWizardNewVDPageSizeLocation::sltMediumSizeChanged(qulonglong /*uSize*/) 347 { 348 349 } 350 351 void UIWizardNewVDPageSizeLocation::sltMediumPathChanged(const QString &/*strPath*/) 352 { 353 354 } 355 334 356 void UIWizardNewVDPageSizeLocation::retranslateUi() 335 357 { … … 340 362 { 341 363 // /* Translate page: */ 342 // retranslateUi(); 364 343 365 344 366 // /* Get default extension for new virtual-disk: */ … … 347 369 // if (m_pLocationEditor) 348 370 // m_pLocationEditor->setText(absoluteFilePath(m_strDefaultName, m_strDefaultPath, m_strDefaultExtension)); 371 372 UIWizardNewVD *pWizard = qobject_cast<UIWizardNewVD*>(wizard()); 373 AssertReturnVoid(pWizard && m_pMediumSizePathGroup); 374 const CMediumFormat comMediumFormat = pWizard->mediumFormat(); 375 AssertReturnVoid(!comMediumFormat.isNull()); 376 377 QString strExtension = UIDiskEditorGroupBox::defaultExtensionForMediumFormat(comMediumFormat); 378 QString strMediumFilePath = 379 UIDiskEditorGroupBox::constructMediumFilePath(UIDiskVariantGroupBox::appendExtension(m_strDefaultName, 380 strExtension), m_strDefaultPath); 381 m_pMediumSizePathGroup->setMediumPath(strMediumFilePath); 382 m_pMediumSizePathGroup->setMediumSize(m_uDefaultSize > m_uMediumSizeMin && m_uDefaultSize < m_uMediumSizeMax ? m_uDefaultSize : m_uMediumSizeMin); 383 retranslateUi(); 349 384 } 350 385 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageSizeLocation.h
r90356 r90400 72 72 // QString m_strDefaultPath; 73 73 // QString m_strDefaultExtension; 74 // qulonglong m_uMediumSizeMin; 75 // qulonglong m_uMediumSizeMax; 74 76 75 // /** @} */ 77 76 … … 101 100 private slots: 102 101 103 /** Location editors stuff: */104 102 void sltSelectLocationButtonClicked(); 103 void sltMediumSizeChanged(qulonglong uSize); 104 void sltMediumPathChanged(const QString &strPath); 105 105 106 106 private: … … 113 113 114 114 UIMediumSizeAndPathGroupBox *m_pMediumSizePathGroup; 115 qulonglong m_uMediumSizeMin; 116 qulonglong m_uMediumSizeMax; 117 QString m_strDefaultName; 118 QString m_strDefaultPath; 119 qulonglong m_uDefaultSize; 120 QSet<QString> m_userModifiedParameters; 115 121 }; 116 122 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVDPageVariant.cpp
r90372 r90400 190 190 void UIWizardNewVDPageVariant::initializePage() 191 191 { 192 retranslateUi();193 192 UIWizardNewVD *pWizard = qobject_cast<UIWizardNewVD*>(wizard()); 194 193 AssertReturnVoid(pWizard && m_pVariantGroupBox); 195 194 setWidgetVisibility(pWizard->mediumFormat()); 196 195 newVDWizardPropertySet(MediumVariant, m_pVariantGroupBox->mediumVariant()); 196 retranslateUi(); 197 197 } 198 198 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMDiskPageBasic.cpp
r90295 r90400 37 37 #include "UIMessageCenter.h" 38 38 #include "UIWizardNewVMDiskPageBasic.h" 39 #include "UIWizardDiskEditors.h" 39 40 40 41 /* COM includes: */ … … 45 46 #include <iprt/path.h> 46 47 47 48 QString UIWizardNewVMDiskPage::defaultExtension(const CMediumFormat &mediumFormatRef)49 {50 if (!mediumFormatRef.isNull())51 {52 /* Load extension / device list: */53 QVector<QString> fileExtensions;54 QVector<KDeviceType> deviceTypes;55 CMediumFormat mediumFormat(mediumFormatRef);56 mediumFormat.DescribeFileExtensions(fileExtensions, deviceTypes);57 for (int i = 0; i < fileExtensions.size(); ++i)58 if (deviceTypes[i] == KDeviceType_HardDisk)59 return fileExtensions[i].toLower();60 }61 AssertMsgFailed(("Extension can't be NULL!\n"));62 return QString();63 }64 65 QString UIWizardNewVMDiskPage::toFileName(const QString &strName, const QString &strExtension)66 {67 /* Convert passed name to native separators (it can be full, actually): */68 QString strFileName = QDir::toNativeSeparators(strName);69 70 /* Remove all trailing dots to avoid multiple dots before extension: */71 int iLen;72 while (iLen = strFileName.length(), iLen > 0 && strFileName[iLen - 1] == '.')73 strFileName.truncate(iLen - 1);74 75 /* Add passed extension if its not done yet: */76 if (QFileInfo(strFileName).suffix().toLower() != strExtension)77 strFileName += QString(".%1").arg(strExtension);78 79 /* Return result: */80 return strFileName;81 }82 83 QString UIWizardNewVMDiskPage::absoluteFilePath(const QString &strFileName, const QString &strPath)84 {85 /* Wrap file-info around received file name: */86 QFileInfo fileInfo(strFileName);87 /* If path-info is relative or there is no path-info at all: */88 if (fileInfo.fileName() == strFileName || fileInfo.isRelative())89 {90 /* Resolve path on the basis of path we have: */91 fileInfo = QFileInfo(strPath, strFileName);92 }93 /* Return full absolute hard disk file path: */94 return QDir::toNativeSeparators(fileInfo.absoluteFilePath());95 }96 48 97 49 QUuid UIWizardNewVMDiskPage::getWithFileOpenDialog(const QString &strOSTypeID, … … 425 377 setWidgetVisibility(pWizard->mediumFormat()); 426 378 } 427 QString strDefaultExtension = UI WizardNewVMDiskPage::defaultExtension(pWizard->mediumFormat());379 QString strDefaultExtension = UIDiskEditorGroupBox::defaultExtensionForMediumFormat(pWizard->mediumFormat()); 428 380 429 381 /* We set the medium name and path according to machine name/path and do not allow user change these in the guided mode: */ … … 431 383 const QString &strMachineFolder = pWizard->machineFolder(); 432 384 QString strMediumPath = 433 UI WizardNewVMDiskPage::absoluteFilePath(UIWizardNewVMDiskPage::toFileName(strDefaultName,385 UIDiskEditorGroupBox::constructMediumFilePath(UIDiskEditorGroupBox::appendExtension(strDefaultName, 434 386 strDefaultExtension), strMachineFolder); 435 387 newVMWizardPropertySet(MediumPath, strMediumPath); -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMDiskPageBasic.h
r90295 r90400 55 55 namespace UIWizardNewVMDiskPage 56 56 { 57 QString defaultExtension(const CMediumFormat &mediumFormatRef);58 QString toFileName(const QString &strName, const QString &strExtension);59 57 QUuid getWithFileOpenDialog(const QString &strOSTypeID, 60 58 const QString &strMachineFolder, 61 59 const QString &strMachineBaseName, 62 60 QWidget *pCaller); 63 QString absoluteFilePath(const QString &strFileName, const QString &strPath);64 61 bool checkFATSizeLimitation(const qulonglong uVariant, const QString &strMediumPath, const qulonglong uSize); 65 62 QString selectNewMediumLocation(UIWizardNewVM *pWizard); -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp
r90362 r90400 707 707 return; 708 708 QString strMediumPath = 709 UI WizardNewVMDiskPage::toFileName(strSelectedPath,710 UIWizardNewVMDiskPage::defaultExtension(pWizard->mediumFormat()));709 UIDiskEditorGroupBox::appendExtension(strSelectedPath, 710 UIDiskEditorGroupBox::defaultExtensionForMediumFormat(pWizard->mediumFormat())); 711 711 QFileInfo mediumPath(strMediumPath); 712 712 m_pSizeAndLocationGroup->setMediumPath(QDir::toNativeSeparators(mediumPath.absoluteFilePath())); … … 812 812 strMediumPath = uiCommon().virtualBox().GetSystemProperties().GetDefaultMachineFolder(); 813 813 } 814 QString strExtension = UI WizardNewVMDiskPage::defaultExtension(pWizard->mediumFormat());814 QString strExtension = UIDiskEditorGroupBox::defaultExtensionForMediumFormat(pWizard->mediumFormat()); 815 815 if (m_pSizeAndLocationGroup) 816 816 { 817 817 QString strMediumFilePath = 818 UI WizardNewVMDiskPage::absoluteFilePath(UIWizardNewVMDiskPage::toFileName(strDiskFileName,818 UIDiskEditorGroupBox::constructMediumFilePath(UIDiskEditorGroupBox::appendExtension(strDiskFileName, 819 819 strExtension), strMediumPath); 820 820 m_pSizeAndLocationGroup->blockSignals(true);
Note:
See TracChangeset
for help on using the changeset viewer.