VirtualBox

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


Ignore:
Timestamp:
Feb 7, 2022 1:02:17 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9515. Passing a reference of CUnattended to new vm wizard to prevent multiple multiple passes over te ISO file. Not complete.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
7 edited

Legend:

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

    r93545 r93638  
    971971        || pItem->itemType() == UIVirtualMachineItemType_Local)
    972972    {
     973        CUnattended comUnattendedInstaller = uiCommon().virtualBox().CreateUnattendedInstaller();
     974        AssertMsg(!comUnattendedInstaller.isNull(), ("Could not create unattended installer!\n"));
     975
    973976        /* Use the "safe way" to open stack of Mac OS X Sheets: */
    974977        QWidget *pWizardParent = windowManager().realParentWindow(this);
    975978        UISafePointerWizardNewVM pWizard = new UIWizardNewVM(pWizardParent, actionPool(),
    976                                                              m_pWidget->fullGroupName(), "gui-createvm");
     979                                                             m_pWidget->fullGroupName(), "gui-createvm", comUnattendedInstaller);
    977980        windowManager().registerNewParent(pWizard, pWizardParent);
    978 
    979         CUnattended comUnattendedInstaller = uiCommon().virtualBox().CreateUnattendedInstaller();
    980         AssertMsg(!comUnattendedInstaller.isNull(), ("Could not create unattended installer!\n"));
    981 
    982         UIUnattendedInstallData unattendedInstallData;
    983         unattendedInstallData.m_strUserName = comUnattendedInstaller.GetUser();
    984         unattendedInstallData.m_strPassword = comUnattendedInstaller.GetPassword();
    985         unattendedInstallData.m_fInstallGuestAdditions = comUnattendedInstaller.GetInstallGuestAdditions();
    986         unattendedInstallData.m_strGuestAdditionsISOPath = comUnattendedInstaller.GetAdditionsIsoPath();
    987         unattendedInstallData.m_uSelectedWindowsImageIndex = comUnattendedInstaller.GetImageIndex();
    988         pWizard->setDefaultUnattendedInstallData(unattendedInstallData);
    989981
    990982        /* Execute wizard: */
    991983        pWizard->exec();
    992984
    993         /* Cache unattended install related info and delete the wizard before handling the unattended install stuff: */
    994         unattendedInstallData = pWizard->unattendedInstallData();
    995 
     985        bool fStartHeadless = pWizard->startHeadless();
     986        bool fUnattendedEnabled = pWizard->isUnattendedEnabled();
     987        QString strMachineId = pWizard->createdMachineId().toString();
    996988        delete pWizard;
    997989        /* Handle unattended install stuff: */
    998         if (unattendedInstallData.m_fUnattendedEnabled)
    999             startUnattendedInstall(comUnattendedInstaller, unattendedInstallData);
     990        if (fUnattendedEnabled)
     991            startUnattendedInstall(comUnattendedInstaller, fStartHeadless, strMachineId);
    1000992    }
    1001993    /* For cloud machine: */
     
    25282520}
    25292521
    2530 void UIVirtualBoxManager::startUnattendedInstall(CUnattended &comUnattendedInstaller, const UIUnattendedInstallData &unattendedData)
     2522void UIVirtualBoxManager::startUnattendedInstall(CUnattended &comUnattendedInstaller,
     2523                                                 bool fStartHeadless, const QString &strMachineId)
    25312524{
    25322525    CVirtualBox comVBox = uiCommon().virtualBox();
    2533     CMachine comMachine = comVBox.FindMachine(unattendedData.m_uMachineUid.toString());
     2526    CMachine comMachine = comVBox.FindMachine(strMachineId);
    25342527    if (comMachine.isNull())
    25352528        return;
    2536 
    2537     if (!QFileInfo(unattendedData.m_strISOPath).exists())
    2538     {
    2539         /// @todo Show a relavant error message here
    2540         return;
    2541     }
    2542 
    2543     comUnattendedInstaller.SetIsoPath(unattendedData.m_strISOPath);
    2544     AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2545     comUnattendedInstaller.SetMachine(comMachine);
    2546     AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2547     comUnattendedInstaller.SetUser(unattendedData.m_strUserName);
    2548     AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2549     comUnattendedInstaller.SetPassword(unattendedData.m_strPassword);
    2550     AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2551     comUnattendedInstaller.SetHostname(unattendedData.m_strHostnameDomainName);
    2552     AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2553     comUnattendedInstaller.SetProductKey(unattendedData.m_strProductKey);
    2554     AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2555     comUnattendedInstaller.SetInstallGuestAdditions(unattendedData.m_fInstallGuestAdditions);
    2556     AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2557     comUnattendedInstaller.SetAdditionsIsoPath(unattendedData.m_strGuestAdditionsISOPath);
    2558     AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2559     if (unattendedData.m_uSelectedWindowsImageIndex != 0)
    2560     {
    2561         comUnattendedInstaller.SetImageIndex(unattendedData.m_uSelectedWindowsImageIndex);
    2562         AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    2563     }
    25642529
    25652530    comUnattendedInstaller.Prepare();
     
    25702535    AssertReturnVoid(checkUnattendedInstallError(comUnattendedInstaller));
    25712536
    2572     UICommon::LaunchMode enmLaunchMode = UICommon::LaunchMode_Default;
    2573     if (unattendedData.m_fStartHeadless)
    2574         enmLaunchMode = UICommon::LaunchMode_Headless;
    2575     launchMachine(comMachine, enmLaunchMode);
     2537    launchMachine(comMachine, fStartHeadless ? UICommon::LaunchMode_Headless : UICommon::LaunchMode_Default);
    25762538}
    25772539
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r93115 r93638  
    371371
    372372        /** Creates an unattended installer and uses it to install guest os to newly created vm. */
    373         void startUnattendedInstall(CUnattended &comUnattendedInstaller, const UIUnattendedInstallData &unattendedData);
     373    void startUnattendedInstall(CUnattended &comUnattendedInstaller, bool fStartHeadless, const QString &strMachineId);
    374374
    375375        /** Launches or shows virtual machines represented by passed @a items in corresponding @a enmLaunchMode (for launch). */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardNewVMEditors.cpp

    r93546 r93638  
    322322bool UIAdditionalUnattendedOptions::isComplete() const
    323323{
     324    return isHostnameComplete();
     325}
     326
     327bool UIAdditionalUnattendedOptions::isHostnameComplete() const
     328{
    324329    if (m_pHostnameDomainNameEditor)
    325330        return m_pHostnameDomainNameEditor->isComplete();
    326331    return false;
    327332}
     333
    328334
    329335void UIAdditionalUnattendedOptions::mark()
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/editors/UIWizardNewVMEditors.h

    r93541 r93638  
    130130        QString hostnameDomainName() const;
    131131        bool isComplete() const;
     132        bool isHostnameComplete() const;
    132133        void mark();
    133134        void disableEnableProductKeyWidgets(bool fEnabled);
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.cpp

    r93568 r93638  
    3636#include "CBIOSSettings.h"
    3737#include "CGraphicsAdapter.h"
     38#include "CExtPackManager.h"
    3839#include "CMediumFormat.h"
     40#include "CStorageController.h"
    3941#include "CUSBController.h"
    4042#include "CUSBDeviceFilters.h"
    41 #include "CExtPackManager.h"
    42 #include "CStorageController.h"
     43#include "CUnattended.h"
    4344
    4445/* Namespaces: */
     
    4647
    4748
    48 UIUnattendedInstallData::UIUnattendedInstallData()
    49     : m_fUnattendedEnabled(false)
    50     , m_fStartHeadless(false)
    51 {
    52 }
    53 
    5449UIWizardNewVM::UIWizardNewVM(QWidget *pParent, UIActionPool *pActionPool,
    55                              const QString &strMachineGroup /* = QString() */,
    56                              const QString &strHelpHashtag /* = QString() */)
     50                             const QString &strMachineGroup, const QString &strHelpHashtag,
     51                             CUnattended &comUnattended)
    5752    : UINativeWizard(pParent, WizardType_NewVM, WizardMode_Auto, strHelpHashtag)
    5853    , m_strMachineGroup(strMachineGroup)
     
    7469    , m_fEmptyDiskRecommended(false)
    7570    , m_pActionPool(pActionPool)
     71    , m_comUnattended(comUnattended)
     72    , m_fStartHeadless(false)
    7673{
    7774#ifndef VBOX_WS_MAC
     
    177174        return false;
    178175    }
    179     return attachDefaultDevices();
     176
     177    if (!attachDefaultDevices())
     178    {
     179        cleanWizard();
     180        return false;
     181    }
     182
     183    if (isUnattendedEnabled())
     184    {
     185        m_comUnattended.SetMachine(m_machine);
     186        if (!checkUnattendedInstallError(m_comUnattended))
     187        {
     188            cleanWizard();
     189            return false;
     190        }
     191    }
     192    return true;
    180193}
    181194
     
    547560}
    548561
    549 void UIWizardNewVM::setDefaultUnattendedInstallData(const UIUnattendedInstallData &unattendedInstallData)
    550 {
    551     m_unattendedInstallData = unattendedInstallData;
    552 }
     562// void UIWizardNewVM::setDefaultUnattendedInstallData(const UIUnattendedInstallData &unattendedInstallData)
     563// {
     564//     m_unattendedInstallData = unattendedInstallData;
     565// }
    553566
    554567CMedium &UIWizardNewVM::virtualDisk()
     
    653666bool UIWizardNewVM::installGuestAdditions() const
    654667{
    655     return m_unattendedInstallData.m_fInstallGuestAdditions;
     668    AssertReturn(!m_comUnattended.isNull(), false);
     669    return m_comUnattended.GetInstallGuestAdditions();
    656670}
    657671
    658672void UIWizardNewVM::setInstallGuestAdditions(bool fInstallGA)
    659673{
    660     m_unattendedInstallData.m_fInstallGuestAdditions = fInstallGA;
     674    AssertReturnVoid(!m_comUnattended.isNull());
     675    m_comUnattended.SetInstallGuestAdditions(fInstallGA);
     676    AssertReturnVoid(checkUnattendedInstallError(m_comUnattended));
    661677}
    662678
    663679bool UIWizardNewVM::startHeadless() const
    664680{
    665     return m_unattendedInstallData.m_fStartHeadless;
     681    return m_fStartHeadless;
    666682}
    667683
    668684void UIWizardNewVM::setStartHeadless(bool fStartHeadless)
    669685{
    670     m_unattendedInstallData.m_fStartHeadless = fStartHeadless;
     686    m_fStartHeadless = fStartHeadless;
    671687}
    672688
     
    693709}
    694710
    695 const QString &UIWizardNewVM::ISOFilePath() const
    696 {
    697     return m_strISOFilePath;
     711QString UIWizardNewVM::ISOFilePath() const
     712{
     713    AssertReturn(!m_comUnattended.isNull(), QString());
     714    return m_comUnattended.GetIsoPath();
    698715}
    699716
    700717void UIWizardNewVM::setISOFilePath(const QString &strISOFilePath)
    701718{
    702     m_strISOFilePath = strISOFilePath;
     719    AssertReturnVoid(!m_comUnattended.isNull());
     720    m_comUnattended.SetIsoPath(strISOFilePath);
    703721    /* We hide/show unattended install page depending on the value of isUnattendedEnabled: */
    704722    setUnattendedPageVisible(isUnattendedEnabled());
    705 }
    706 
    707 const QString &UIWizardNewVM::userName() const
    708 {
    709     return m_unattendedInstallData.m_strUserName;
     723    AssertReturnVoid(checkUnattendedInstallError(m_comUnattended));
     724}
     725
     726QString UIWizardNewVM::userName() const
     727{
     728    AssertReturn(!m_comUnattended.isNull(), QString());
     729    return m_comUnattended.GetUser();
    710730}
    711731
    712732void UIWizardNewVM::setUserName(const QString &strUserName)
    713733{
    714     m_unattendedInstallData.m_strUserName = strUserName;
    715 }
    716 
    717 const QString &UIWizardNewVM::password() const
    718 {
    719     return m_unattendedInstallData.m_strPassword;
     734    AssertReturnVoid(!m_comUnattended.isNull());
     735    m_comUnattended.SetUser(strUserName);
     736    AssertReturnVoid(checkUnattendedInstallError(m_comUnattended));
     737}
     738
     739QString UIWizardNewVM::password() const
     740{
     741    AssertReturn(!m_comUnattended.isNull(), QString());
     742    return m_comUnattended.GetPassword();
    720743}
    721744
    722745void UIWizardNewVM::setPassword(const QString &strPassword)
    723746{
    724     m_unattendedInstallData.m_strPassword = strPassword;
    725 }
    726 
    727 const QString &UIWizardNewVM::guestAdditionsISOPath() const
    728 {
    729     return m_unattendedInstallData.m_strGuestAdditionsISOPath;
     747    AssertReturnVoid(!m_comUnattended.isNull());
     748    m_comUnattended.SetPassword(strPassword);
     749    AssertReturnVoid(checkUnattendedInstallError(m_comUnattended));
     750}
     751
     752QString UIWizardNewVM::guestAdditionsISOPath() const
     753{
     754    AssertReturn(!m_comUnattended.isNull(), QString());
     755    return m_comUnattended.GetAdditionsIsoPath();
    730756}
    731757
    732758void UIWizardNewVM::setGuestAdditionsISOPath(const QString &strGAISOPath)
    733759{
    734     m_unattendedInstallData.m_strGuestAdditionsISOPath = strGAISOPath;
    735 }
    736 
    737 const QString &UIWizardNewVM::hostnameDomainName() const
    738 {
    739     return m_unattendedInstallData.m_strHostnameDomainName;
     760    AssertReturnVoid(!m_comUnattended.isNull());
     761    m_comUnattended.SetAdditionsIsoPath(strGAISOPath);
     762    AssertReturnVoid(checkUnattendedInstallError(m_comUnattended));
     763}
     764
     765QString UIWizardNewVM::hostnameDomainName() const
     766{
     767    AssertReturn(!m_comUnattended.isNull(), QString());
     768    return m_comUnattended.GetHostname();
    740769}
    741770
    742771void UIWizardNewVM::setHostnameDomainName(const QString &strHostnameDomain)
    743772{
    744     m_unattendedInstallData.m_strHostnameDomainName = strHostnameDomain;
    745 }
    746 
    747 const QString &UIWizardNewVM::productKey() const
    748 {
    749     return m_unattendedInstallData.m_strProductKey;
     773    AssertReturnVoid(!m_comUnattended.isNull());
     774    m_comUnattended.SetHostname(strHostnameDomain);
     775    AssertReturnVoid(checkUnattendedInstallError(m_comUnattended));
     776}
     777
     778QString UIWizardNewVM::productKey() const
     779{
     780    AssertReturn(!m_comUnattended.isNull(), QString());
     781    return  m_comUnattended.GetProductKey();
    750782}
    751783
    752784void UIWizardNewVM::setProductKey(const QString &productKey)
    753785{
    754     m_unattendedInstallData.m_strProductKey = productKey;
     786    AssertReturnVoid(!m_comUnattended.isNull());
     787    m_comUnattended.SetProductKey(productKey);
     788    AssertReturnVoid(checkUnattendedInstallError(m_comUnattended));
    755789}
    756790
     
    856890void UIWizardNewVM::setSelectedWindowImageIndex(ulong uIndex)
    857891{
    858     m_unattendedInstallData.m_uSelectedWindowsImageIndex = uIndex;
     892    AssertReturnVoid(!m_comUnattended.isNull());
     893    m_comUnattended.SetImageIndex(uIndex);
     894    AssertReturnVoid(checkUnattendedInstallError(m_comUnattended));
    859895}
    860896
    861897ulong UIWizardNewVM::selectedWindowImageIndex() const
    862898{
    863     return m_unattendedInstallData.m_uSelectedWindowsImageIndex;
     899    AssertReturn(!m_comUnattended.isNull(), 0);
     900    return m_comUnattended.GetImageIndex();
    864901}
    865902
     
    877914}
    878915
    879 const UIUnattendedInstallData &UIWizardNewVM::unattendedInstallData() const
    880 {
    881     m_unattendedInstallData.m_strISOPath = m_strISOFilePath;
    882     m_unattendedInstallData.m_fUnattendedEnabled = isUnattendedEnabled();
    883     m_unattendedInstallData.m_uMachineUid = createdMachineId();
    884 
    885     return m_unattendedInstallData;
    886 }
    887 
    888916bool UIWizardNewVM::isUnattendedEnabled() const
    889917{
    890     if (m_strISOFilePath.isEmpty() || m_strISOFilePath.isNull())
     918    if (m_comUnattended.isNull())
     919        return false;
     920    if (m_comUnattended.GetIsoPath().isEmpty())
    891921        return false;
    892922    if (m_fSkipUnattendedInstall)
     
    916946        setPageVisible(m_iUnattendedInstallPageIndex, fVisible);
    917947}
     948
     949bool UIWizardNewVM::checkUnattendedInstallError(const CUnattended &comUnattended) const
     950{
     951    if (!comUnattended.isOk())
     952    {
     953        UINotificationMessage::cannotRunUnattendedGuestInstall(comUnattended);
     954        return false;
     955    }
     956    return true;
     957}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.h

    r93545 r93638  
    4343};
    4444
    45 /** Container for unattended install related data. */
    46 struct UIUnattendedInstallData
    47 {
    48     UIUnattendedInstallData();
    49     QUuid m_uMachineUid;
    50     QString m_strISOPath;
    51 
    52     bool m_fUnattendedEnabled;
    53     bool m_fStartHeadless;
    54     QString m_strUserName;
    55     QString m_strPassword;
    56     QString m_strHostnameDomainName;
    57     QString m_strProductKey;
    58     bool m_fInstallGuestAdditions;
    59     QString m_strGuestAdditionsISOPath;
    60     /* 0 is for no selection. */
    61     ulong m_uSelectedWindowsImageIndex;
    62 #if 0
    63     QString m_strDetectedOSVersion;
    64     QString m_strDetectedOSFlavor;
    65     QString m_strDetectedOSLanguages;
    66     QString m_strDetectedOSHints;
    67 #endif
    68 };
    69 
    70 
    7145/** New Virtual Machine wizard: */
    7246class UIWizardNewVM : public UINativeWizard
     
    7751
    7852    UIWizardNewVM(QWidget *pParent, UIActionPool *pActionPool,
    79                   const QString &strMachineGroup = QString(), const QString &strHelpHashtag = QString());
     53                  const QString &strMachineGroup, const QString &strHelpHashtag, CUnattended &comUnattended);
    8054    bool isUnattendedEnabled() const;
    8155    bool isOSTypeDetectionOK() const;
    82     void setDefaultUnattendedInstallData(const UIUnattendedInstallData &unattendedInstallData);
    83     const UIUnattendedInstallData &unattendedInstallData() const;
    8456    bool isGuestOSTypeWindows() const;
    8557
     
    9264
    9365    const QString &machineGroup() const;
     66    QUuid createdMachineId() const;
    9467
    9568    /** @name Setter/getters for vm parameters
     
    131104        void setEFIEnabled(bool fEnabled);
    132105
    133         const QString &ISOFilePath() const;
     106        QString ISOFilePath() const;
    134107        void setISOFilePath(const QString &strISOFilePath);
    135108
    136         const QString &userName() const;
     109        QString userName() const;
    137110        void setUserName(const QString &strUserName);
    138111
    139         const QString &password() const;
     112        QString password() const;
    140113        void setPassword(const QString &strPassword);
    141114
    142         const QString &guestAdditionsISOPath() const;
     115        QString guestAdditionsISOPath() const;
    143116        void setGuestAdditionsISOPath(const QString &strGAISOPath);
    144117
    145         const QString &hostnameDomainName() const;
     118        QString hostnameDomainName() const;
    146119        void setHostnameDomainName(const QString &strHostnameDomainName);
    147120
    148         const QString &productKey() const;
     121        QString productKey() const;
    149122        void setProductKey(const QString &productKey);
    150123
     
    200173    QString getNextControllerName(KStorageBus type);
    201174    void setUnattendedPageVisible(bool fVisible);
    202     /** Returns the Id of newly created VM. */
    203     QUuid createdMachineId() const;
    204175    void deleteVirtualDisk();
    205 
     176    bool checkUnattendedInstallError(const CUnattended &comUnattended) const;
    206177    /** @name Variables
    207178     * @{ */
     
    215186       int m_iSASCount;
    216187       int m_iUSBCount;
    217        mutable UIUnattendedInstallData m_unattendedInstallData;
    218 
    219        /** Path of the ISO file attached to the new vm. Possibly used for the unattended install. */
    220        QString m_strISOFilePath;
    221188
    222189       /** Path of the folder created by this wizard page. Used to remove previously created
     
    259226       QVector<KMediumVariant> m_mediumVariants;
    260227       UIActionPool *m_pActionPool;
     228       CUnattended &m_comUnattended;
     229       bool m_fStartHeadless;
    261230    /** @} */
    262231};
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMExpertPage.cpp

    r93607 r93638  
    959959    m_pAdditionalOptionsContainer->setDomainName("myguest.virtualbox.org");
    960960    /* Initialize unattended hostname here since we cannot get the default value from CUnattended this early (unlike username etc): */
    961     pWizard->setHostnameDomainName(m_pAdditionalOptionsContainer->hostnameDomainName());
     961    if (m_pAdditionalOptionsContainer->isHostnameComplete())
     962        pWizard->setHostnameDomainName(m_pAdditionalOptionsContainer->hostnameDomainName());
    962963
    963964    m_pAdditionalOptionsContainer->blockSignals(false);
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