VirtualBox

Changeset 77186 in vbox


Ignore:
Timestamp:
Feb 6, 2019 7:52:33 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
128675
Message:

FE/Qt: bugref:9340. Remove an intermediate popup dialog in machine settings storage attachement

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  
    27352735}
    27362736
    2737 QUuid VBoxGlobal::openMediumSelectorDialog(QWidget *pParent, UIMediumDeviceType  enmMediumType,
    2738                                            const QString &strMachineName, const QString &strMachineFolder,
    2739                                            const QString &strMachineGuestOSTypeId  /* = QString() */)
     2737int VBoxGlobal::openMediumSelectorDialog(QWidget *pParent, UIMediumDeviceType  enmMediumType, QUuid &outUuid,
     2738                                         const QString &strMachineName, const QString &strMachineFolder,
     2739                                         const QString &strMachineGuestOSTypeId  /* = QString() */)
    27402740{
    27412741    QWidget *pDialogParent = windowManager().realParentWindow(pParent);
     
    27442744
    27452745    if (!pSelector)
    2746         return QUuid();
     2746        return static_cast<int>(UIMediumSelector::ReturnCode_Rejected);
     2747
    27472748    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)
    27492759    {
    27502760        QList<QUuid> selectedMediumIds = pSelector->selectedMediumIds();
    2751         delete pSelector;
     2761
    27522762        /* Currently we only care about the 0th since we support single selection by intention: */
    27532763        if (selectedMediumIds.isEmpty())
    2754             return QUuid();
     2764            returnCode = UIMediumSelector::ReturnCode_Rejected;
    27552765        else
    2756             return selectedMediumIds[0];
     2766            outUuid = selectedMediumIds[0];
    27572767    }
    27582768    delete pSelector;
    2759     return QUuid();
     2769    return static_cast<int>(returnCode);
    27602770}
    27612771
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r77170 r77186  
    518518          * @param  strMachineFolder         Passes the machine folder,
    519519          * @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,
    522523                                       const QString &strMachineName, const QString &strMachineFolder,
    523524                                       const QString &strMachineGuestOSTypeId = QString());
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp

    r77181 r77186  
    6363    , m_enmMediumType(enmMediumType)
    6464    , m_pButtonBox(0)
     65    , m_pCancelButton(0)
     66    , m_pChooseButton(0)
     67    , m_pLeaveEmptyButton(0)
    6568    , m_pMainMenu(0)
    6669    , m_pToolBar(0)
     
    123126    }
    124127
    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"));
    127134
    128135    if (m_pTreeWidget)
     
    231238    }
    232239
    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
    238247
    239248    if (m_pSearchWidget)
     
    382391    {
    383392        /* 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);
    386401
    387402        /* Add button-box into main layout: */
     
    390405
    391406    repopulateTreeWidget();
     407}
     408
     409void UIMediumSelector::sltButtonChoose()
     410{
     411    done(static_cast<int>(ReturnCode_Accepted));
     412}
     413
     414void UIMediumSelector::sltButtonCancel()
     415{
     416    done(static_cast<int>(ReturnCode_Rejected));
     417}
     418
     419void UIMediumSelector::sltButtonLeaveEmpty()
     420{
     421    done(static_cast<int>(ReturnCode_LeftEmpty));
    392422}
    393423
     
    423453void UIMediumSelector::sltHandleItemSelectionChanged()
    424454{
    425     updateOkButton();
     455    updateChooseButton();
    426456}
    427457
     
    517547}
    518548
    519 void UIMediumSelector::updateOkButton()
    520 {
    521 
    522     if (!m_pTreeWidget || !m_pButtonBox || !m_pButtonBox->button(QDialogButtonBox::Ok))
     549void UIMediumSelector::updateChooseButton()
     550{
     551
     552    if (!m_pTreeWidget || !m_pChooseButton)
    523553        return;
    524554    QList<QTreeWidgetItem*> selectedItems = m_pTreeWidget->selectedItems();
    525555    if (selectedItems.isEmpty())
    526556    {
    527         m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
     557        m_pChooseButton->setEnabled(false);
    528558        return;
    529559    }
     
    537567    }
    538568    if (mediumItemSelected)
    539         m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
     569        m_pChooseButton->setEnabled(true);
    540570    else
    541         m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
     571        m_pChooseButton->setEnabled(false);
    542572}
    543573
     
    628658    restoreSelection(selectedMedia, menuItemVector);
    629659    saveDefaultForeground();
    630     updateOkButton();
     660    updateChooseButton();
    631661    if (m_pAttachedSubTreeRoot)
    632662        m_pTreeWidget->expandItem(m_pAttachedSubTreeRoot);
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.h

    r77170 r77186  
    5757    QList<QUuid> selectedMediumIds() const;
    5858
     59    enum ReturnCode
     60    {
     61        ReturnCode_Rejected = 0,
     62        ReturnCode_Accepted,
     63        ReturnCode_LeftEmpty,
     64        ReturnCode_Max
     65    };
     66
    5967protected:
    6068
    6169    void showEvent(QShowEvent *pEvent);
    6270
     71
    6372private slots:
    6473
     74    void sltButtonLeaveEmpty();
     75    void sltButtonCancel();
     76    void sltButtonChoose();
    6577    void sltAddMedium();
    6678    void sltCreateMedium();
     
    98110    void          repopulateTreeWidget();
    99111    /** Disable/enable 'ok' button on the basis of having a selected item */
    100     void          updateOkButton();
     112    void          updateChooseButton();
    101113    UIMediumItem* addTreeItem(const UIMedium &medium, QITreeWidgetItem *pParent);
    102114    void          restoreSelection(const QList<QUuid> &selectedMediums, QVector<UIMediumItem*> &mediumList);
     
    113125    UIMediumDeviceType    m_enmMediumType;
    114126    QIDialogButtonBox    *m_pButtonBox;
     127    QPushButton          *m_pCancelButton;
     128    QPushButton          *m_pChooseButton;
     129    QPushButton          *m_pLeaveEmptyButton;
    115130    QMenu                *m_pMainMenu;
    116131    UIToolBar            *m_pToolBar;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp

    r77170 r77186  
    37983798    const QString strMachineFolder(QFileInfo(m_strMachineSettingsFilePath).absolutePath());
    37993799
    3800     bool fCancelled = false;
    3801     bool fCreateEmpty = false;
    38023800    QUuid uMediumId;
     3801    int iAnswer = static_cast<int>(UIMediumSelector::ReturnCode_Rejected);
    38033802    switch (enmDevice)
    38043803    {
    38053804        case KDeviceType_HardDisk:
    38063805        {
    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);
    38163809            break;
    38173810        }
    38183811        case KDeviceType_DVD:
    38193812        {
    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);
    38293815            break;
    38303816        }
    38313817        case KDeviceType_Floppy:
    38323818        {
    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);
    38443821        }
    38453822        default: break; /* Shut up, MSC! */
    38463823    }
    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();
    38573844}
    38583845
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic3.cpp

    r77170 r77186  
    2828#include "UIMediaComboBox.h"
    2929#include "UIMedium.h"
     30#include "UIMediumSelector.h"
    3031#include "UIMessageCenter.h"
    3132#include "UIWizardNewVD.h"
     
    6263{
    6364    /* 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())
    6974    {
    7075        /* Update medium-combo if necessary: */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette