1 | /* $Id: UIWizardCloneVD.cpp 90271 2021-07-21 10:11:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardCloneVD class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2021 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* GUI includes: */
|
---|
19 | #include "UICommon.h"
|
---|
20 | #include "UIMedium.h"
|
---|
21 | #include "UIMessageCenter.h"
|
---|
22 | #include "UIWizardCloneVD.h"
|
---|
23 | #include "UIWizardCloneVDPageBasic1.h"
|
---|
24 | #include "UIWizardCloneVDPageBasic2.h"
|
---|
25 | #include "UIWizardCloneVDPageBasic3.h"
|
---|
26 | #include "UIWizardCloneVDPageExpert.h"
|
---|
27 |
|
---|
28 | /* COM includes: */
|
---|
29 | #include "CMediumFormat.h"
|
---|
30 |
|
---|
31 |
|
---|
32 | UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const CMedium &comSourceVirtualDisk)
|
---|
33 | : UIWizard(pParent, WizardType_CloneVD)
|
---|
34 | , m_comSourceVirtualDisk(comSourceVirtualDisk)
|
---|
35 | , m_enmSourceVirtualDiskDeviceType(m_comSourceVirtualDisk.GetDeviceType())
|
---|
36 | {
|
---|
37 | #ifndef VBOX_WS_MAC
|
---|
38 | /* Assign watermark: */
|
---|
39 | assignWatermark(":/wizard_new_harddisk.png");
|
---|
40 | #else /* VBOX_WS_MAC */
|
---|
41 | /* Assign background image: */
|
---|
42 | assignBackground(":/wizard_new_harddisk_bg.png");
|
---|
43 | #endif /* VBOX_WS_MAC */
|
---|
44 | }
|
---|
45 |
|
---|
46 | bool UIWizardCloneVD::copyVirtualDisk()
|
---|
47 | {
|
---|
48 | /* Gather attributes: */
|
---|
49 | const CMediumFormat comMediumFormat = field("mediumFormat").value<CMediumFormat>();
|
---|
50 | const qulonglong uVariant = field("mediumVariant").toULongLong();
|
---|
51 | const QString strMediumPath = field("mediumPath").toString();
|
---|
52 | const qulonglong uSize = field("mediumSize").toULongLong();
|
---|
53 | /* Check attributes: */
|
---|
54 | AssertReturn(!strMediumPath.isNull(), false);
|
---|
55 | AssertReturn(uSize > 0, false);
|
---|
56 |
|
---|
57 | /* Get VBox object: */
|
---|
58 | CVirtualBox comVBox = uiCommon().virtualBox();
|
---|
59 |
|
---|
60 | /* Create new virtual disk image: */
|
---|
61 | CMedium comVirtualDisk = comVBox.CreateMedium(comMediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, m_enmSourceVirtualDiskDeviceType);
|
---|
62 | if (!comVBox.isOk())
|
---|
63 | {
|
---|
64 | msgCenter().cannotCreateMediumStorage(comVBox, strMediumPath, this);
|
---|
65 | return false;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /* Compose medium-variant: */
|
---|
69 | QVector<KMediumVariant> variants(sizeof(qulonglong) * 8);
|
---|
70 | for (int i = 0; i < variants.size(); ++i)
|
---|
71 | {
|
---|
72 | qulonglong temp = uVariant;
|
---|
73 | temp &= Q_UINT64_C(1) << i;
|
---|
74 | variants[i] = (KMediumVariant)temp;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /* Copy source image to new one: */
|
---|
78 | CProgress comProgress = m_comSourceVirtualDisk.CloneTo(comVirtualDisk, variants, CMedium());
|
---|
79 | if (!m_comSourceVirtualDisk.isOk())
|
---|
80 | {
|
---|
81 | msgCenter().cannotCreateMediumStorage(m_comSourceVirtualDisk, strMediumPath, this);
|
---|
82 | return false;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /* Show creation progress: */
|
---|
86 | msgCenter().showModalProgressDialog(comProgress, windowTitle(), ":/progress_media_create_90px.png", this);
|
---|
87 | if (comProgress.GetCanceled())
|
---|
88 | return false;
|
---|
89 | if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
|
---|
90 | {
|
---|
91 | msgCenter().cannotCreateMediumStorage(comProgress, strMediumPath, this);
|
---|
92 | return false;
|
---|
93 | }
|
---|
94 |
|
---|
95 | /* Make sure we register the medium to VBox: */
|
---|
96 | uiCommon().createMedium(UIMedium(comVirtualDisk, UIMediumDeviceType_HardDisk, KMediumState_Created));
|
---|
97 |
|
---|
98 | /* Positive: */
|
---|
99 | return true;
|
---|
100 | }
|
---|
101 |
|
---|
102 | void UIWizardCloneVD::retranslateUi()
|
---|
103 | {
|
---|
104 | /* Call to base-class: */
|
---|
105 | UIWizard::retranslateUi();
|
---|
106 |
|
---|
107 | /* Translate wizard: */
|
---|
108 | setWindowTitle(tr("Copy Virtual Disk Image"));
|
---|
109 | setButtonText(QWizard::FinishButton, tr("Copy"));
|
---|
110 | }
|
---|
111 |
|
---|
112 | void UIWizardCloneVD::prepare()
|
---|
113 | {
|
---|
114 | /* Create corresponding pages: */
|
---|
115 | switch (mode())
|
---|
116 | {
|
---|
117 | case WizardMode_Basic:
|
---|
118 | {
|
---|
119 | setPage(Page1, new UIWizardCloneVDPageBasic1(m_enmSourceVirtualDiskDeviceType));
|
---|
120 | setPage(Page2, new UIWizardCloneVDPageBasic2(m_enmSourceVirtualDiskDeviceType));
|
---|
121 | setPage(Page3, new UIWizardCloneVDPageBasic3);
|
---|
122 | break;
|
---|
123 | }
|
---|
124 | case WizardMode_Expert:
|
---|
125 | {
|
---|
126 | setPage(PageExpert, new UIWizardCloneVDPageExpert(m_enmSourceVirtualDiskDeviceType));
|
---|
127 | break;
|
---|
128 | }
|
---|
129 | default:
|
---|
130 | {
|
---|
131 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
132 | break;
|
---|
133 | }
|
---|
134 | }
|
---|
135 | /* Call to base-class: */
|
---|
136 | UIWizard::prepare();
|
---|
137 | }
|
---|