VirtualBox

Changeset 83855 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 20, 2020 1:36:50 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Rework add VM stuff to be more universal; Soon it will be handling cloud stuff as well.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r83854 r83855  
    292292                    uiCommon().launchMachine(comMachine);
    293293                else
    294                     sltOpenAddMachineDialog(strFile);
     294                    openAddMachineDialog(strFile);
    295295            }
    296296            /* And has allowed VBox OVF file extension: */
     
    465465    UIQObjectPropertySetter guardBlock(actionPool()->action(UIActionIndexST_M_File_S_ImportAppliance), "opened", true);
    466466    connect(&guardBlock, &UIQObjectPropertySetter::sigAboutToBeDestroyed,
    467     this, &UIVirtualBoxManager::sltHandleUpdateActionAppearanceRequest);
     467            this, &UIVirtualBoxManager::sltHandleUpdateActionAppearanceRequest);
    468468    updateActionsAppearance();
    469469
     
    557557}
    558558
    559 void UIVirtualBoxManager::sltOpenAddMachineDialog(const QString &strFileName /* = QString() */)
    560 {
    561     /* Initialize variables: */
    562 #ifdef VBOX_WS_MAC
    563     QString strTmpFile = ::darwinResolveAlias(strFileName);
    564 #else
    565     QString strTmpFile = strFileName;
    566 #endif
    567     CVirtualBox comVBox = uiCommon().virtualBox();
    568 
     559void UIVirtualBoxManager::sltOpenAddMachineDialog()
     560{
    569561    /* Lock the actions preventing cascade calls: */
    570562    UIQObjectPropertySetter guardBlock(QList<QObject*>() << actionPool()->action(UIActionIndexST_M_Welcome_S_Add)
     
    576568    updateActionsAppearance();
    577569
    578     /* No file specified: */
    579     if (strTmpFile.isEmpty())
    580     {
    581         QString strBaseFolder = comVBox.GetSystemProperties().GetDefaultMachineFolder();
    582         QString strTitle = tr("Select a virtual machine file");
    583         QStringList extensions;
    584         for (int i = 0; i < VBoxFileExts.size(); ++i)
    585             extensions << QString("*.%1").arg(VBoxFileExts[i]);
    586         QString strFilter = tr("Virtual machine files (%1)").arg(extensions.join(" "));
    587         /* Create open file dialog: */
    588         QStringList fileNames = QIFileDialog::getOpenFileNames(strBaseFolder, strFilter, this, strTitle, 0, true, true);
    589         if (!fileNames.isEmpty())
    590             strTmpFile = fileNames.at(0);
    591     }
    592 
    593     /* Nothing was chosen? */
    594     if (strTmpFile.isEmpty())
    595         return;
    596 
    597     /* Make sure this machine can be opened: */
    598     CMachine comMachineNew = comVBox.OpenMachine(strTmpFile);
    599     if (!comVBox.isOk())
    600     {
    601         msgCenter().cannotOpenMachine(comVBox, strTmpFile);
    602         return;
    603     }
    604 
    605     /* Make sure this machine was NOT registered already: */
    606     CMachine comMachineOld = comVBox.FindMachine(comMachineNew.GetId().toString());
    607     if (!comMachineOld.isNull())
    608     {
    609         msgCenter().cannotReregisterExistingMachine(strTmpFile, comMachineOld.GetName());
    610         return;
    611     }
    612 
    613     /* Register that machine: */
    614     comVBox.RegisterMachine(comMachineNew);
     570    /* Open add machine dialog: */
     571    openAddMachineDialog();
    615572}
    616573
     
    14361393    /* 'Welcome' menu connections: */
    14371394    connect(actionPool()->action(UIActionIndexST_M_Welcome_S_Add), &UIAction::triggered,
    1438             this, &UIVirtualBoxManager::sltOpenAddMachineDialogDefault);
     1395            this, &UIVirtualBoxManager::sltOpenAddMachineDialog);
    14391396
    14401397    /* 'Group' menu connections: */
    14411398    connect(actionPool()->action(UIActionIndexST_M_Group_S_Add), &UIAction::triggered,
    1442             this, &UIVirtualBoxManager::sltOpenAddMachineDialogDefault);
     1399            this, &UIVirtualBoxManager::sltOpenAddMachineDialog);
    14431400    connect(actionPool()->action(UIActionIndexST_M_Group_M_StartOrShow), &UIAction::triggered,
    14441401            this, &UIVirtualBoxManager::sltPerformStartOrShowMachine);
     
    14581415    /* 'Machine' menu connections: */
    14591416    connect(actionPool()->action(UIActionIndexST_M_Machine_S_Add), &UIAction::triggered,
    1460             this, &UIVirtualBoxManager::sltOpenAddMachineDialogDefault);
     1417            this, &UIVirtualBoxManager::sltOpenAddMachineDialog);
    14611418    connect(actionPool()->action(UIActionIndexST_M_Machine_S_Settings), &UIAction::triggered,
    14621419            this, &UIVirtualBoxManager::sltOpenMachineSettingsDialogDefault);
     
    16321589}
    16331590
     1591void UIVirtualBoxManager::openAddMachineDialog(const QString &strFileName /* = QString() */)
     1592{
     1593    /* Initialize variables: */
     1594#ifdef VBOX_WS_MAC
     1595    QString strTmpFile = ::darwinResolveAlias(strFileName);
     1596#else
     1597    QString strTmpFile = strFileName;
     1598#endif
     1599    CVirtualBox comVBox = uiCommon().virtualBox();
     1600
     1601    /* No file specified: */
     1602    if (strTmpFile.isEmpty())
     1603    {
     1604        QString strBaseFolder = comVBox.GetSystemProperties().GetDefaultMachineFolder();
     1605        QString strTitle = tr("Select a virtual machine file");
     1606        QStringList extensions;
     1607        for (int i = 0; i < VBoxFileExts.size(); ++i)
     1608            extensions << QString("*.%1").arg(VBoxFileExts[i]);
     1609        QString strFilter = tr("Virtual machine files (%1)").arg(extensions.join(" "));
     1610        /* Create open file dialog: */
     1611        QStringList fileNames = QIFileDialog::getOpenFileNames(strBaseFolder, strFilter, this, strTitle, 0, true, true);
     1612        if (!fileNames.isEmpty())
     1613            strTmpFile = fileNames.at(0);
     1614    }
     1615
     1616    /* Nothing was chosen? */
     1617    if (strTmpFile.isEmpty())
     1618        return;
     1619
     1620    /* Make sure this machine can be opened: */
     1621    CMachine comMachineNew = comVBox.OpenMachine(strTmpFile);
     1622    if (!comVBox.isOk())
     1623    {
     1624        msgCenter().cannotOpenMachine(comVBox, strTmpFile);
     1625        return;
     1626    }
     1627
     1628    /* Make sure this machine was NOT registered already: */
     1629    CMachine comMachineOld = comVBox.FindMachine(comMachineNew.GetId().toString());
     1630    if (!comMachineOld.isNull())
     1631    {
     1632        msgCenter().cannotReregisterExistingMachine(strTmpFile, comMachineOld.GetName());
     1633        return;
     1634    }
     1635
     1636    /* Register that machine: */
     1637    comVBox.RegisterMachine(comMachineNew);
     1638}
     1639
    16341640void UIVirtualBoxManager::performStartOrShowVirtualMachines(const QList<UIVirtualMachineItem*> &items, UICommon::LaunchMode enmLaunchMode)
    16351641{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r83854 r83855  
    185185    /** @name Machine menu stuff.
    186186      * @{ */
    187         /** Handles call to open Add Machine dialog.
    188           * @param strFileName can bring the name of file to add machine from. */
    189         void sltOpenAddMachineDialog(const QString &strFileName = QString());
    190         /** Handles call to open Add Machine dialog the default way. */
    191         void sltOpenAddMachineDialogDefault() { sltOpenAddMachineDialog(); }
     187        /** Handles call to open add machine dialog. */
     188        void sltOpenAddMachineDialog();
    192189
    193190        /** Handles call to open Machine Settings dialog.
     
    304301        /** Returns whether single cloud profile group is selected. */
    305302        bool isSingleCloudProfileGroupSelected() const;
     303    /** @} */
     304
     305    /** @name VM add stuff.
     306      * @{ */
     307        /** Opens add machine dialog specifying initial name with @a strFileName. */
     308        void openAddMachineDialog(const QString &strFileName = QString());
    306309    /** @} */
    307310
Note: See TracChangeset for help on using the changeset viewer.

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