1 | /* $Id: UIWizardCloneVD.cpp 90301 2021-07-23 12:47:15Z 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 "UINotificationCenter.h"
|
---|
23 | #include "UIWizardCloneVD.h"
|
---|
24 | #include "UIWizardCloneVDPageBasic1.h"
|
---|
25 | #include "UIWizardCloneVDPageBasic2.h"
|
---|
26 | #include "UIWizardCloneVDPageBasic3.h"
|
---|
27 | #include "UIWizardCloneVDPageExpert.h"
|
---|
28 |
|
---|
29 | /* COM includes: */
|
---|
30 | #include "CMediumFormat.h"
|
---|
31 |
|
---|
32 |
|
---|
33 | UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const CMedium &comSourceVirtualDisk)
|
---|
34 | : UIWizard(pParent, WizardType_CloneVD)
|
---|
35 | , m_comSourceVirtualDisk(comSourceVirtualDisk)
|
---|
36 | , m_enmSourceVirtualDiskDeviceType(m_comSourceVirtualDisk.GetDeviceType())
|
---|
37 | {
|
---|
38 | #ifndef VBOX_WS_MAC
|
---|
39 | /* Assign watermark: */
|
---|
40 | assignWatermark(":/wizard_new_harddisk.png");
|
---|
41 | #else /* VBOX_WS_MAC */
|
---|
42 | /* Assign background image: */
|
---|
43 | assignBackground(":/wizard_new_harddisk_bg.png");
|
---|
44 | #endif /* VBOX_WS_MAC */
|
---|
45 | }
|
---|
46 |
|
---|
47 | bool UIWizardCloneVD::copyVirtualDisk()
|
---|
48 | {
|
---|
49 | /* Gather attributes: */
|
---|
50 | const CMediumFormat comMediumFormat = field("mediumFormat").value<CMediumFormat>();
|
---|
51 | const qulonglong uVariant = field("mediumVariant").toULongLong();
|
---|
52 | const QString strMediumPath = field("mediumPath").toString();
|
---|
53 | const qulonglong uSize = field("mediumSize").toULongLong();
|
---|
54 | /* Check attributes: */
|
---|
55 | AssertReturn(!strMediumPath.isNull(), false);
|
---|
56 | AssertReturn(uSize > 0, false);
|
---|
57 |
|
---|
58 | /* Get VBox object: */
|
---|
59 | CVirtualBox comVBox = uiCommon().virtualBox();
|
---|
60 |
|
---|
61 | /* Create new virtual disk image: */
|
---|
62 | CMedium comVirtualDisk = comVBox.CreateMedium(comMediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, m_enmSourceVirtualDiskDeviceType);
|
---|
63 | if (!comVBox.isOk())
|
---|
64 | {
|
---|
65 | msgCenter().cannotCreateMediumStorage(comVBox, strMediumPath, this);
|
---|
66 | return false;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /* Compose medium-variant: */
|
---|
70 | QVector<KMediumVariant> variants(sizeof(qulonglong) * 8);
|
---|
71 | for (int i = 0; i < variants.size(); ++i)
|
---|
72 | {
|
---|
73 | qulonglong temp = uVariant;
|
---|
74 | temp &= Q_UINT64_C(1) << i;
|
---|
75 | variants[i] = (KMediumVariant)temp;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* Copy medium: */
|
---|
79 | UINotificationProgressMediumCopy *pNotification = new UINotificationProgressMediumCopy(m_comSourceVirtualDisk,
|
---|
80 | comVirtualDisk,
|
---|
81 | variants);
|
---|
82 | connect(pNotification, &UINotificationProgressMediumCopy::sigMediumCopied,
|
---|
83 | &uiCommon(), &UICommon::sltHandleMediumCreated);
|
---|
84 | notificationCenter().append(pNotification);
|
---|
85 |
|
---|
86 | /* Positive: */
|
---|
87 | return true;
|
---|
88 | }
|
---|
89 |
|
---|
90 | void UIWizardCloneVD::retranslateUi()
|
---|
91 | {
|
---|
92 | /* Call to base-class: */
|
---|
93 | UIWizard::retranslateUi();
|
---|
94 |
|
---|
95 | /* Translate wizard: */
|
---|
96 | setWindowTitle(tr("Copy Virtual Disk Image"));
|
---|
97 | setButtonText(QWizard::FinishButton, tr("Copy"));
|
---|
98 | }
|
---|
99 |
|
---|
100 | void UIWizardCloneVD::prepare()
|
---|
101 | {
|
---|
102 | /* Create corresponding pages: */
|
---|
103 | switch (mode())
|
---|
104 | {
|
---|
105 | case WizardMode_Basic:
|
---|
106 | {
|
---|
107 | setPage(Page1, new UIWizardCloneVDPageBasic1(m_enmSourceVirtualDiskDeviceType));
|
---|
108 | setPage(Page2, new UIWizardCloneVDPageBasic2(m_enmSourceVirtualDiskDeviceType));
|
---|
109 | setPage(Page3, new UIWizardCloneVDPageBasic3);
|
---|
110 | break;
|
---|
111 | }
|
---|
112 | case WizardMode_Expert:
|
---|
113 | {
|
---|
114 | setPage(PageExpert, new UIWizardCloneVDPageExpert(m_enmSourceVirtualDiskDeviceType));
|
---|
115 | break;
|
---|
116 | }
|
---|
117 | default:
|
---|
118 | {
|
---|
119 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
120 | break;
|
---|
121 | }
|
---|
122 | }
|
---|
123 | /* Call to base-class: */
|
---|
124 | UIWizard::prepare();
|
---|
125 | }
|
---|