Changeset 90731 in vbox
- Timestamp:
- Aug 18, 2021 5:28:18 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVM.cpp
r90714 r90731 20 20 #include "UIMessageCenter.h" 21 21 #include "UINotificationCenter.h" 22 #include "UIProgressObject.h" 22 23 #include "UIWizardCloneVM.h" 23 24 #include "UIWizardCloneVMPageBasic1.h" … … 138 139 bool UIWizardCloneVM::cloneVM() 139 140 { 140 /* Get VBox object: */141 CVirtualBox vbox = uiCommon().virtualBox();142 143 141 /* Prepare machine for cloning: */ 144 142 CMachine srcMachine = m_machine; … … 150 148 if (m_fLinkedClone && m_snapshot.isNull()) 151 149 { 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 } 152 157 153 158 /* 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()) 156 161 return false; 157 162 158 /* Preparemachine: */159 CMachine machine = session.GetMachine();163 /* Acquire session machine: */ 164 CMachine comSessionMachine = comSession.GetMachine(); 160 165 161 166 /* 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); 163 168 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()) 172 174 { 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); 174 200 return false; 175 201 } … … 177 203 else 178 204 { 179 msgCenter().cannotTakeSnapshot( machine, m_machine.GetName(), this);205 msgCenter().cannotTakeSnapshot(comSessionMachine, strMachineName, this); 180 206 return false; 181 207 } 182 208 183 209 /* 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()) 189 215 { 190 216 msgCenter().cannotFindSnapshotByName(m_machine, strSnapshotName, this); 191 217 return false; 192 218 } 193 srcMachine = newSnapshot.GetMachine(); 219 220 /* Update machine for cloning finally: */ 221 srcMachine = comCreatedSnapshot.GetMachine(); 194 222 } 195 223 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()) 199 229 { 200 msgCenter().cannotCreateMachine( vbox, this);230 msgCenter().cannotCreateMachine(comVBox, this); 201 231 return false; 202 232 } … … 216 246 break; 217 247 } 218 219 248 if (m_fKeepDiskNames) 220 249 options.append(KCloneOptions_KeepDiskNames); 221 250 if (m_fKeepHardwareUUIDs) 222 251 options.append(KCloneOptions_KeepHwUUIDs); 223 224 252 /* Linked clones requested? */ 225 253 if (m_fLinkedClone)
Note:
See TracChangeset
for help on using the changeset viewer.

