Changeset 77186 in vbox for trunk/src/VBox
- Timestamp:
- Feb 6, 2019 7:52:33 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 128675
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r77170 r77186 2735 2735 } 2736 2736 2737 QUuid VBoxGlobal::openMediumSelectorDialog(QWidget *pParent, UIMediumDeviceType enmMediumType,2738 2739 2737 int VBoxGlobal::openMediumSelectorDialog(QWidget *pParent, UIMediumDeviceType enmMediumType, QUuid &outUuid, 2738 const QString &strMachineName, const QString &strMachineFolder, 2739 const QString &strMachineGuestOSTypeId /* = QString() */) 2740 2740 { 2741 2741 QWidget *pDialogParent = windowManager().realParentWindow(pParent); … … 2744 2744 2745 2745 if (!pSelector) 2746 return QUuid(); 2746 return static_cast<int>(UIMediumSelector::ReturnCode_Rejected); 2747 2747 2748 windowManager().registerNewParent(pSelector, pDialogParent); 2748 if (pSelector->exec(false)) 2749 2750 int iResult = pSelector->exec(false); 2751 UIMediumSelector::ReturnCode returnCode; 2752 2753 if (iResult >= static_cast<int>(UIMediumSelector::ReturnCode_Max) || iResult < 0) 2754 returnCode = UIMediumSelector::ReturnCode_Rejected; 2755 else 2756 returnCode = static_cast<UIMediumSelector::ReturnCode>(iResult); 2757 2758 if (returnCode == UIMediumSelector::ReturnCode_Accepted) 2749 2759 { 2750 2760 QList<QUuid> selectedMediumIds = pSelector->selectedMediumIds(); 2751 delete pSelector; 2761 2752 2762 /* Currently we only care about the 0th since we support single selection by intention: */ 2753 2763 if (selectedMediumIds.isEmpty()) 2754 return QUuid();2764 returnCode = UIMediumSelector::ReturnCode_Rejected; 2755 2765 else 2756 returnselectedMediumIds[0];2766 outUuid = selectedMediumIds[0]; 2757 2767 } 2758 2768 delete pSelector; 2759 return QUuid();2769 return static_cast<int>(returnCode); 2760 2770 } 2761 2771 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r77170 r77186 518 518 * @param strMachineFolder Passes the machine folder, 519 519 * @param strMachineGuestOSTypeId Passes the type ID of machine's guest os, 520 * returns the ID of the selected/created medium if successful, a null QUuid otherwise.*/ 521 QUuid openMediumSelectorDialog(QWidget *pParent, UIMediumDeviceType enmMediumType, 520 * returns the return code of the UIMediumSelector::ReturnCode as int. In case of a medium selection 521 * UUID of the selected medium is stored in @param outUuid.*/ 522 int openMediumSelectorDialog(QWidget *pParent, UIMediumDeviceType enmMediumType, QUuid &outUuid, 522 523 const QString &strMachineName, const QString &strMachineFolder, 523 524 const QString &strMachineGuestOSTypeId = QString()); -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp
r77181 r77186 63 63 , m_enmMediumType(enmMediumType) 64 64 , m_pButtonBox(0) 65 , m_pCancelButton(0) 66 , m_pChooseButton(0) 67 , m_pLeaveEmptyButton(0) 65 68 , m_pMainMenu(0) 66 69 , m_pToolBar(0) … … 123 126 } 124 127 125 if (m_pButtonBox) 126 m_pButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Choose")); 128 if (m_pCancelButton) 129 m_pCancelButton->setText(tr("Cancel")); 130 if (m_pLeaveEmptyButton) 131 m_pLeaveEmptyButton->setText(tr("Leave Empty")); 132 if (m_pChooseButton) 133 m_pChooseButton->setText(tr("Choose")); 127 134 128 135 if (m_pTreeWidget) … … 231 238 } 232 239 233 if (m_pButtonBox) 234 { 235 connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIMediumSelector::close); 236 connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIMediumSelector::accept); 237 } 240 if (m_pCancelButton) 241 connect(m_pCancelButton, &QPushButton::clicked, this, &UIMediumSelector::sltButtonCancel); 242 if (m_pChooseButton) 243 connect(m_pChooseButton, &QPushButton::clicked, this, &UIMediumSelector::sltButtonChoose); 244 if (m_pLeaveEmptyButton) 245 connect(m_pLeaveEmptyButton, &QPushButton::clicked, this, &UIMediumSelector::sltButtonLeaveEmpty); 246 238 247 239 248 if (m_pSearchWidget) … … 382 391 { 383 392 /* Configure button-box: */ 384 m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); 385 m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape); 393 m_pCancelButton = m_pButtonBox->addButton(tr("Cancel"), QDialogButtonBox::RejectRole); 394 395 /* Only DVDs and Floppies can be left empty: */ 396 if (m_enmMediumType == UIMediumDeviceType_DVD || m_enmMediumType == UIMediumDeviceType_Floppy) 397 m_pLeaveEmptyButton = m_pButtonBox->addButton(tr("Leave Empty"), QDialogButtonBox::ActionRole); 398 399 m_pChooseButton = m_pButtonBox->addButton(tr("Choose"), QDialogButtonBox::AcceptRole); 400 m_pCancelButton->setShortcut(Qt::Key_Escape); 386 401 387 402 /* Add button-box into main layout: */ … … 390 405 391 406 repopulateTreeWidget(); 407 } 408 409 void UIMediumSelector::sltButtonChoose() 410 { 411 done(static_cast<int>(ReturnCode_Accepted)); 412 } 413 414 void UIMediumSelector::sltButtonCancel() 415 { 416 done(static_cast<int>(ReturnCode_Rejected)); 417 } 418 419 void UIMediumSelector::sltButtonLeaveEmpty() 420 { 421 done(static_cast<int>(ReturnCode_LeftEmpty)); 392 422 } 393 423 … … 423 453 void UIMediumSelector::sltHandleItemSelectionChanged() 424 454 { 425 update OkButton();455 updateChooseButton(); 426 456 } 427 457 … … 517 547 } 518 548 519 void UIMediumSelector::update OkButton()520 { 521 522 if (!m_pTreeWidget || !m_p ButtonBox || !m_pButtonBox->button(QDialogButtonBox::Ok))549 void UIMediumSelector::updateChooseButton() 550 { 551 552 if (!m_pTreeWidget || !m_pChooseButton) 523 553 return; 524 554 QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems(); 525 555 if (selectedItems.isEmpty()) 526 556 { 527 m_p ButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);557 m_pChooseButton->setEnabled(false); 528 558 return; 529 559 } … … 537 567 } 538 568 if (mediumItemSelected) 539 m_p ButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);569 m_pChooseButton->setEnabled(true); 540 570 else 541 m_p ButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);571 m_pChooseButton->setEnabled(false); 542 572 } 543 573 … … 628 658 restoreSelection(selectedMedia, menuItemVector); 629 659 saveDefaultForeground(); 630 update OkButton();660 updateChooseButton(); 631 661 if (m_pAttachedSubTreeRoot) 632 662 m_pTreeWidget->expandItem(m_pAttachedSubTreeRoot); -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.h
r77170 r77186 57 57 QList<QUuid> selectedMediumIds() const; 58 58 59 enum ReturnCode 60 { 61 ReturnCode_Rejected = 0, 62 ReturnCode_Accepted, 63 ReturnCode_LeftEmpty, 64 ReturnCode_Max 65 }; 66 59 67 protected: 60 68 61 69 void showEvent(QShowEvent *pEvent); 62 70 71 63 72 private slots: 64 73 74 void sltButtonLeaveEmpty(); 75 void sltButtonCancel(); 76 void sltButtonChoose(); 65 77 void sltAddMedium(); 66 78 void sltCreateMedium(); … … 98 110 void repopulateTreeWidget(); 99 111 /** Disable/enable 'ok' button on the basis of having a selected item */ 100 void update OkButton();112 void updateChooseButton(); 101 113 UIMediumItem* addTreeItem(const UIMedium &medium, QITreeWidgetItem *pParent); 102 114 void restoreSelection(const QList<QUuid> &selectedMediums, QVector<UIMediumItem*> &mediumList); … … 113 125 UIMediumDeviceType m_enmMediumType; 114 126 QIDialogButtonBox *m_pButtonBox; 127 QPushButton *m_pCancelButton; 128 QPushButton *m_pChooseButton; 129 QPushButton *m_pLeaveEmptyButton; 115 130 QMenu *m_pMainMenu; 116 131 UIToolBar *m_pToolBar; -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp
r77170 r77186 3798 3798 const QString strMachineFolder(QFileInfo(m_strMachineSettingsFilePath).absolutePath()); 3799 3799 3800 bool fCancelled = false;3801 bool fCreateEmpty = false;3802 3800 QUuid uMediumId; 3801 int iAnswer = static_cast<int>(UIMediumSelector::ReturnCode_Rejected); 3803 3802 switch (enmDevice) 3804 3803 { 3805 3804 case KDeviceType_HardDisk: 3806 3805 { 3807 const int iAnswer = msgCenter().confirmHardDiskAttachmentCreation(strControllerName, this); 3808 if (iAnswer == AlertButton_Choice1) 3809 uMediumId = vboxGlobal().createHDWithNewHDWizard(this, m_strMachineGuestOSTypeId, m_strMachineSettingsFilePath); 3810 else if (iAnswer == AlertButton_Choice2) 3811 uMediumId = vboxGlobal().openMediumSelectorDialog(this, UIMediumDeviceType_HardDisk, 3812 m_strMachineName, m_strMachineSettingsFilePath, 3813 m_strMachineGuestOSTypeId); 3814 else if (iAnswer == AlertButton_Cancel) 3815 fCancelled = true; 3806 iAnswer = vboxGlobal().openMediumSelectorDialog(this, UIMediumDeviceType_HardDisk, uMediumId, 3807 m_strMachineName, m_strMachineSettingsFilePath, 3808 m_strMachineGuestOSTypeId); 3816 3809 break; 3817 3810 } 3818 3811 case KDeviceType_DVD: 3819 3812 { 3820 int iAnswer = msgCenter().confirmOpticalAttachmentCreation(strControllerName, this); 3821 if (iAnswer == AlertButton_Choice2) 3822 uMediumId = vboxGlobal().openMediumSelectorDialog(this, UIMediumDeviceType_DVD, 3823 m_strMachineName, m_strMachineSettingsFilePath); 3824 /* For optical medium we allow creating an empty drive: */ 3825 else if (iAnswer == AlertButton_Choice1) 3826 fCreateEmpty = true; 3827 else if (iAnswer == AlertButton_Cancel) 3828 fCancelled = true; 3813 iAnswer = vboxGlobal().openMediumSelectorDialog(this, UIMediumDeviceType_DVD, uMediumId, 3814 m_strMachineName, m_strMachineSettingsFilePath); 3829 3815 break; 3830 3816 } 3831 3817 case KDeviceType_Floppy: 3832 3818 { 3833 int iAnswer = msgCenter().confirmFloppyAttachmentCreation(strControllerName, this); 3834 if (iAnswer == AlertButton_Choice2) 3835 uMediumId = vboxGlobal().openMediumSelectorDialog(this, UIMediumDeviceType_Floppy, 3836 m_strMachineName, m_strMachineSettingsFilePath); 3837 3838 /* We allow creating an empty floppy drive: */ 3839 else if (iAnswer == AlertButton_Choice1) 3840 fCreateEmpty = true; 3841 else if (iAnswer == AlertButton_Cancel) 3842 fCancelled = true; 3843 break; 3819 iAnswer = vboxGlobal().openMediumSelectorDialog(this, UIMediumDeviceType_Floppy, uMediumId, 3820 m_strMachineName, m_strMachineSettingsFilePath); 3844 3821 } 3845 3822 default: break; /* Shut up, MSC! */ 3846 3823 } 3847 3848 if (!fCancelled && (!uMediumId.isNull() || fCreateEmpty)) 3849 { 3850 m_pModelStorage->addAttachment(QUuid(m_pModelStorage->data(index, StorageModel::R_ItemId).toString()), enmDevice, uMediumId); 3851 m_pModelStorage->sort(); 3852 emit sigStorageChanged(); 3853 3854 /* Revalidate: */ 3855 revalidate(); 3856 } 3824 /* continue only if iAnswer is either UIMediumSelector::ReturnCode_Accepted or UIMediumSelector::ReturnCode_LeftEmpty: */ 3825 if (iAnswer != static_cast<int>(UIMediumSelector::ReturnCode_Accepted) && 3826 iAnswer != static_cast<int>(UIMediumSelector::ReturnCode_LeftEmpty)) 3827 return; 3828 3829 /* Only DVDs and floppy can be created empty: */ 3830 if (iAnswer == static_cast<int>(UIMediumSelector::ReturnCode_LeftEmpty) && 3831 (enmDevice != KDeviceType_DVD && enmDevice != KDeviceType_Floppy)) 3832 return; 3833 3834 /* if iAnswer is UIMediumSelector::ReturnCode_Accepted then we have to have a valid uMediumId: */ 3835 if (iAnswer == static_cast<int>(UIMediumSelector::ReturnCode_Accepted) && uMediumId.isNull()) 3836 return; 3837 3838 m_pModelStorage->addAttachment(QUuid(m_pModelStorage->data(index, StorageModel::R_ItemId).toString()), enmDevice, uMediumId); 3839 m_pModelStorage->sort(); 3840 emit sigStorageChanged(); 3841 3842 /* Revalidate: */ 3843 revalidate(); 3857 3844 } 3858 3845 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic3.cpp
r77170 r77186 28 28 #include "UIMediaComboBox.h" 29 29 #include "UIMedium.h" 30 #include "UIMediumSelector.h" 30 31 #include "UIMessageCenter.h" 31 32 #include "UIWizardNewVD.h" … … 62 63 { 63 64 /* Get opened medium id: */ 64 QUuid uMediumId = vboxGlobal().openMediumSelectorDialog(thisImp(), UIMediumDeviceType_HardDisk, 65 fieldImp("machineBaseName").toString(), 66 fieldImp("machineFolder").toString(), 67 fieldImp("type").value<CGuestOSType>().GetFamilyId()); 68 if (!uMediumId.isNull()) 65 QUuid uMediumId; 66 67 int returnCode = vboxGlobal().openMediumSelectorDialog(thisImp(), UIMediumDeviceType_HardDisk, 68 uMediumId, 69 fieldImp("machineBaseName").toString(), 70 fieldImp("machineFolder").toString(), 71 fieldImp("type").value<CGuestOSType>().GetFamilyId()); 72 73 if (returnCode == static_cast<int>(UIMediumSelector::ReturnCode_Accepted) && !uMediumId.isNull()) 69 74 { 70 75 /* Update medium-combo if necessary: */
Note:
See TracChangeset
for help on using the changeset viewer.