1 | /* $Id: UIWizardCloneVD.cpp 72696 2018-06-26 16:13:10Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardCloneVD class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2017 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 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* GUI includes: */
|
---|
23 | # include "UIWizardCloneVD.h"
|
---|
24 | # include "UIWizardCloneVDPageBasic1.h"
|
---|
25 | # include "UIWizardCloneVDPageBasic2.h"
|
---|
26 | # include "UIWizardCloneVDPageBasic3.h"
|
---|
27 | # include "UIWizardCloneVDPageBasic4.h"
|
---|
28 | # include "UIWizardCloneVDPageExpert.h"
|
---|
29 | # include "VBoxGlobal.h"
|
---|
30 | # include "UIMessageCenter.h"
|
---|
31 |
|
---|
32 | /* COM includes: */
|
---|
33 | # include "CMediumFormat.h"
|
---|
34 |
|
---|
35 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
36 |
|
---|
37 |
|
---|
38 | UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const CMedium &comSourceVirtualDisk)
|
---|
39 | : UIWizard(pParent, WizardType_CloneVD)
|
---|
40 | , m_comSourceVirtualDisk(comSourceVirtualDisk)
|
---|
41 | , m_enmSourceVirtualDiskDeviceType(m_comSourceVirtualDisk.GetDeviceType())
|
---|
42 | {
|
---|
43 | #ifndef VBOX_WS_MAC
|
---|
44 | /* Assign watermark: */
|
---|
45 | assignWatermark(":/wizard_new_harddisk.png");
|
---|
46 | #else /* VBOX_WS_MAC */
|
---|
47 | /* Assign background image: */
|
---|
48 | assignBackground(":/wizard_new_harddisk_bg.png");
|
---|
49 | #endif /* VBOX_WS_MAC */
|
---|
50 | }
|
---|
51 |
|
---|
52 | bool UIWizardCloneVD::copyVirtualDisk()
|
---|
53 | {
|
---|
54 | /* Gather attributes: */
|
---|
55 | CMedium comSourceVirtualDisk = field("sourceVirtualDisk").value<CMedium>();
|
---|
56 | const CMediumFormat comMediumFormat = field("mediumFormat").value<CMediumFormat>();
|
---|
57 | const qulonglong uVariant = field("mediumVariant").toULongLong();
|
---|
58 | const QString strMediumPath = field("mediumPath").toString();
|
---|
59 | const qulonglong uSize = field("mediumSize").toULongLong();
|
---|
60 | /* Check attributes: */
|
---|
61 | AssertReturn(!strMediumPath.isNull(), false);
|
---|
62 | AssertReturn(uSize > 0, false);
|
---|
63 |
|
---|
64 | /* Get VBox object: */
|
---|
65 | CVirtualBox comVBox = vboxGlobal().virtualBox();
|
---|
66 |
|
---|
67 | /* Create new virtual disk image: */
|
---|
68 | CMedium comVirtualDisk = comVBox.CreateMedium(comMediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, m_enmSourceVirtualDiskDeviceType);
|
---|
69 | if (!comVBox.isOk())
|
---|
70 | {
|
---|
71 | msgCenter().cannotCreateMediumStorage(comVBox, strMediumPath, this);
|
---|
72 | return false;
|
---|
73 | }
|
---|
74 |
|
---|
75 | /* Compose medium-variant: */
|
---|
76 | QVector<KMediumVariant> variants(sizeof(qulonglong) * 8);
|
---|
77 | for (int i = 0; i < variants.size(); ++i)
|
---|
78 | {
|
---|
79 | qulonglong temp = uVariant;
|
---|
80 | temp &= Q_UINT64_C(1) << i;
|
---|
81 | variants[i] = (KMediumVariant)temp;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /* Copy source image to new one: */
|
---|
85 | CProgress comProgress = comSourceVirtualDisk.CloneTo(comVirtualDisk, variants, CMedium());
|
---|
86 | if (!comSourceVirtualDisk.isOk())
|
---|
87 | {
|
---|
88 | msgCenter().cannotCreateMediumStorage(comSourceVirtualDisk, strMediumPath, this);
|
---|
89 | return false;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /* Show creation progress: */
|
---|
93 | msgCenter().showModalProgressDialog(comProgress, windowTitle(), ":/progress_media_create_90px.png", this);
|
---|
94 | if (comProgress.GetCanceled())
|
---|
95 | return false;
|
---|
96 | if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
|
---|
97 | {
|
---|
98 | msgCenter().cannotCreateMediumStorage(comProgress, strMediumPath, this);
|
---|
99 | return false;
|
---|
100 | }
|
---|
101 |
|
---|
102 | /* Save created image as target one: */
|
---|
103 | m_comTargetVirtualDisk = comVirtualDisk;
|
---|
104 |
|
---|
105 | /* Just close the created image, it is not required anymore: */
|
---|
106 | m_comTargetVirtualDisk.Close();
|
---|
107 |
|
---|
108 | return true;
|
---|
109 | }
|
---|
110 |
|
---|
111 | void UIWizardCloneVD::retranslateUi()
|
---|
112 | {
|
---|
113 | /* Call to base-class: */
|
---|
114 | UIWizard::retranslateUi();
|
---|
115 |
|
---|
116 | /* Translate wizard: */
|
---|
117 | setWindowTitle(tr("Copy Virtual Disk Image"));
|
---|
118 | setButtonText(QWizard::FinishButton, tr("Copy"));
|
---|
119 | }
|
---|
120 |
|
---|
121 | void UIWizardCloneVD::prepare()
|
---|
122 | {
|
---|
123 | /* Create corresponding pages: */
|
---|
124 | switch (mode())
|
---|
125 | {
|
---|
126 | case WizardMode_Basic:
|
---|
127 | {
|
---|
128 | setPage(Page1, new UIWizardCloneVDPageBasic1(m_comSourceVirtualDisk,
|
---|
129 | m_enmSourceVirtualDiskDeviceType));
|
---|
130 | setPage(Page2, new UIWizardCloneVDPageBasic2(m_enmSourceVirtualDiskDeviceType));
|
---|
131 | setPage(Page3, new UIWizardCloneVDPageBasic3(m_enmSourceVirtualDiskDeviceType));
|
---|
132 | setPage(Page4, new UIWizardCloneVDPageBasic4);
|
---|
133 | break;
|
---|
134 | }
|
---|
135 | case WizardMode_Expert:
|
---|
136 | {
|
---|
137 | setPage(PageExpert, new UIWizardCloneVDPageExpert(m_comSourceVirtualDisk,
|
---|
138 | m_enmSourceVirtualDiskDeviceType));
|
---|
139 | break;
|
---|
140 | }
|
---|
141 | default:
|
---|
142 | {
|
---|
143 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
144 | break;
|
---|
145 | }
|
---|
146 | }
|
---|
147 | /* Call to base-class: */
|
---|
148 | UIWizard::prepare();
|
---|
149 | }
|
---|
150 |
|
---|