VirtualBox

Changeset 90731 in vbox for trunk


Ignore:
Timestamp:
Aug 18, 2021 5:28:18 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10067: Clone VM wizard: Handle internal snapshot creation via UIProgressObject, not UIProgressDialog.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVM.cpp

    r90714 r90731  
    2020#include "UIMessageCenter.h"
    2121#include "UINotificationCenter.h"
     22#include "UIProgressObject.h"
    2223#include "UIWizardCloneVM.h"
    2324#include "UIWizardCloneVMPageBasic1.h"
     
    138139bool UIWizardCloneVM::cloneVM()
    139140{
    140     /* Get VBox object: */
    141     CVirtualBox vbox = uiCommon().virtualBox();
    142 
    143141    /* Prepare machine for cloning: */
    144142    CMachine srcMachine = m_machine;
     
    150148    if (m_fLinkedClone && m_snapshot.isNull())
    151149    {
     150        /* Acquire machine name beforehand: */
     151        const QString strMachineName = m_machine.GetName();
     152        if (!m_machine.isOk())
     153        {
     154            msgCenter().cannotAcquireMachineParameter(m_machine);
     155            return false;
     156        }
    152157
    153158        /* Open session: */
    154         CSession session = uiCommon().openSession(m_machine.GetId());
    155         if (session.isNull())
     159        CSession comSession = uiCommon().openSession(m_machine.GetId());
     160        if (comSession.isNull())
    156161            return false;
    157162
    158         /* Prepare machine: */
    159         CMachine machine = session.GetMachine();
     163        /* Acquire session machine: */
     164        CMachine comSessionMachine = comSession.GetMachine();
    160165
    161166        /* Take the snapshot: */
    162         QString strSnapshotName = tr("Linked Base for %1 and %2").arg(m_machine.GetName()).arg(m_strCloneName);
     167        const QString strSnapshotName = tr("Linked Base for %1 and %2").arg(strMachineName).arg(m_strCloneName);
    163168        QUuid uSnapshotId;
    164         CProgress progress = machine.TakeSnapshot(strSnapshotName, "", true, uSnapshotId);
    165 
    166         if (machine.isOk())
    167         {
    168             /* Show the "Taking Snapshot" progress dialog: */
    169             msgCenter().showModalProgressDialog(progress, m_machine.GetName(), ":/progress_snapshot_create_90px.png", this);
    170 
    171             if (!progress.isOk() || progress.GetResultCode() != 0)
     169        CProgress comProgress = comSessionMachine.TakeSnapshot(strSnapshotName, "", true, uSnapshotId);
     170        if (comSessionMachine.isOk())
     171        {
     172            /* Make sure progress valid: */
     173            if (!comProgress.isNull() && !comProgress.GetCompleted())
    172174            {
    173                 msgCenter().cannotTakeSnapshot(progress, m_machine.GetName(), this);
     175                /* Create take snapshot progress object: */
     176                QPointer<UIProgressObject> pObject = new UIProgressObject(comProgress, this);
     177                if (pObject)
     178                {
     179                    connect(pObject.data(), &UIProgressObject::sigProgressChange,
     180                            this, &UIWizardCloneVM::sltHandleProgressChange);
     181                    connect(pObject.data(), &UIProgressObject::sigProgressComplete,
     182                            this, &UIWizardCloneVM::sltHandleProgressFinished);
     183                    sltHandleProgressStarted();
     184                    pObject->exec();
     185                    if (pObject)
     186                        delete pObject;
     187                    else
     188                    {
     189                        // Premature application shutdown,
     190                        // exit immediately:
     191                        return false;
     192                    }
     193                }
     194            }
     195
     196            /* Check progress for errors: */
     197            if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
     198            {
     199                msgCenter().cannotTakeSnapshot(comProgress, strMachineName, this);
    174200                return false;
    175201            }
     
    177203        else
    178204        {
    179             msgCenter().cannotTakeSnapshot(machine, m_machine.GetName(), this);
     205            msgCenter().cannotTakeSnapshot(comSessionMachine, strMachineName, this);
    180206            return false;
    181207        }
    182208
    183209        /* Unlock machine finally: */
    184         session.UnlockMachine();
    185 
    186         /* Get the new snapshot and the snapshot machine. */
    187         const CSnapshot &newSnapshot = m_machine.FindSnapshot(uSnapshotId.toString());
    188         if (newSnapshot.isNull())
     210        comSession.UnlockMachine();
     211
     212        /* Look for created snapshot: */
     213        const CSnapshot comCreatedSnapshot = m_machine.FindSnapshot(uSnapshotId.toString());
     214        if (comCreatedSnapshot.isNull())
    189215        {
    190216            msgCenter().cannotFindSnapshotByName(m_machine, strSnapshotName, this);
    191217            return false;
    192218        }
    193         srcMachine = newSnapshot.GetMachine();
     219
     220        /* Update machine for cloning finally: */
     221        srcMachine = comCreatedSnapshot.GetMachine();
    194222    }
    195223
    196     /* Create a new machine object. */
    197     CMachine cloneMachine = vbox.CreateMachine(m_strCloneFilePath, m_strCloneName, QVector<QString>(), QString(), QString());
    198     if (!vbox.isOk())
     224    /* Get VBox object: */
     225    CVirtualBox comVBox = uiCommon().virtualBox();
     226    /* Create a new machine object: */
     227    CMachine cloneMachine = comVBox.CreateMachine(m_strCloneFilePath, m_strCloneName, QVector<QString>(), QString(), QString());
     228    if (!comVBox.isOk())
    199229    {
    200         msgCenter().cannotCreateMachine(vbox, this);
     230        msgCenter().cannotCreateMachine(comVBox, this);
    201231        return false;
    202232    }
     
    216246            break;
    217247    }
    218 
    219248    if (m_fKeepDiskNames)
    220249        options.append(KCloneOptions_KeepDiskNames);
    221250    if (m_fKeepHardwareUUIDs)
    222251        options.append(KCloneOptions_KeepHwUUIDs);
    223 
    224252    /* Linked clones requested? */
    225253    if (m_fLinkedClone)
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