1 | /* $Id: UIWizardNewVD.cpp 91061 2021-09-01 14:30:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardNewVD class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 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 "UIMessageCenter.h"
|
---|
21 | #include "UINotificationCenter.h"
|
---|
22 | #include "UIWizardNewVD.h"
|
---|
23 | #include "UIWizardNewVDFileTypePage.h"
|
---|
24 | #include "UIWizardNewVDVariantPage.h"
|
---|
25 | #include "UIWizardNewVDSizeLocationPage.h"
|
---|
26 | #include "UIWizardNewVDExpertPage.h"
|
---|
27 |
|
---|
28 | UIWizardNewVD::UIWizardNewVD(QWidget *pParent,
|
---|
29 | const QString &strDefaultName,
|
---|
30 | const QString &strDefaultPath,
|
---|
31 | qulonglong uDefaultSize,
|
---|
32 | WizardMode mode)
|
---|
33 | : UINativeWizard(pParent, WizardType_NewVD, mode)
|
---|
34 | , m_strDefaultName(strDefaultName)
|
---|
35 | , m_strDefaultPath(strDefaultPath)
|
---|
36 | , m_uDefaultSize(uDefaultSize)
|
---|
37 | , m_iMediumVariantPageIndex(-1)
|
---|
38 | {
|
---|
39 | #ifndef VBOX_WS_MAC
|
---|
40 | /* Assign watermark: */
|
---|
41 | setPixmapName(":/wizard_new_harddisk.png");
|
---|
42 | #else /* VBOX_WS_MAC */
|
---|
43 | /* Assign background image: */
|
---|
44 | setPixmapName(":/wizard_new_harddisk_bg.png");
|
---|
45 | #endif /* VBOX_WS_MAC */
|
---|
46 | }
|
---|
47 |
|
---|
48 | qulonglong UIWizardNewVD::mediumVariant() const
|
---|
49 | {
|
---|
50 | return m_uMediumVariant;
|
---|
51 | }
|
---|
52 |
|
---|
53 | void UIWizardNewVD::setMediumVariant(qulonglong uMediumVariant)
|
---|
54 | {
|
---|
55 | m_uMediumVariant = uMediumVariant;
|
---|
56 | }
|
---|
57 |
|
---|
58 | const CMediumFormat &UIWizardNewVD::mediumFormat()
|
---|
59 | {
|
---|
60 | return m_comMediumFormat;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void UIWizardNewVD::setMediumFormat(const CMediumFormat &mediumFormat)
|
---|
64 | {
|
---|
65 | m_comMediumFormat = mediumFormat;
|
---|
66 | if (mode() == WizardMode_Basic)
|
---|
67 | setMediumVariantPageVisibility();
|
---|
68 | }
|
---|
69 |
|
---|
70 | const QString &UIWizardNewVD::mediumPath() const
|
---|
71 | {
|
---|
72 | return m_strMediumPath;
|
---|
73 | }
|
---|
74 |
|
---|
75 | void UIWizardNewVD::setMediumPath(const QString &strMediumPath)
|
---|
76 | {
|
---|
77 | m_strMediumPath = strMediumPath;
|
---|
78 | }
|
---|
79 |
|
---|
80 | qulonglong UIWizardNewVD::mediumSize() const
|
---|
81 | {
|
---|
82 | return m_uMediumSize;
|
---|
83 | }
|
---|
84 |
|
---|
85 | void UIWizardNewVD::setMediumSize(qulonglong uMediumSize)
|
---|
86 | {
|
---|
87 | m_uMediumSize = uMediumSize;
|
---|
88 | }
|
---|
89 |
|
---|
90 | void UIWizardNewVD::populatePages()
|
---|
91 | {
|
---|
92 | switch (mode())
|
---|
93 | {
|
---|
94 | case WizardMode_Basic:
|
---|
95 | {
|
---|
96 | addPage(new UIWizardNewVDFileTypePage);
|
---|
97 | m_iMediumVariantPageIndex = addPage(new UIWizardNewVDVariantPage);
|
---|
98 | addPage(new UIWizardNewVDSizeLocationPage(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
|
---|
99 | break;
|
---|
100 | }
|
---|
101 | case WizardMode_Expert:
|
---|
102 | {
|
---|
103 | addPage(new UIWizardNewVDExpertPage(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
|
---|
104 | break;
|
---|
105 | }
|
---|
106 | default:
|
---|
107 | {
|
---|
108 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
109 | break;
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | bool UIWizardNewVD::createVirtualDisk()
|
---|
115 | {
|
---|
116 | AssertReturn(!m_strMediumPath.isNull(), false);
|
---|
117 | AssertReturn(m_uMediumSize > 0, false);
|
---|
118 |
|
---|
119 | /* Get VBox object: */
|
---|
120 | CVirtualBox comVBox = uiCommon().virtualBox();
|
---|
121 |
|
---|
122 | /* Create new virtual disk image: */
|
---|
123 | CMedium comVirtualDisk = comVBox.CreateMedium(m_comMediumFormat.GetName(),
|
---|
124 | m_strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk);
|
---|
125 | if (!comVBox.isOk())
|
---|
126 | {
|
---|
127 | msgCenter().cannotCreateMediumStorage(comVBox, m_strMediumPath, this);
|
---|
128 | return false;
|
---|
129 | }
|
---|
130 |
|
---|
131 | /* Compose medium-variant: */
|
---|
132 | QVector<KMediumVariant> variants(sizeof(qulonglong) * 8);
|
---|
133 | for (int i = 0; i < variants.size(); ++i)
|
---|
134 | {
|
---|
135 | qulonglong temp = m_uMediumVariant;
|
---|
136 | temp &= Q_UINT64_C(1) << i;
|
---|
137 | variants[i] = (KMediumVariant)temp;
|
---|
138 | }
|
---|
139 |
|
---|
140 | UINotificationProgressMediumCreate *pNotification = new UINotificationProgressMediumCreate(comVirtualDisk,
|
---|
141 | m_uMediumSize,
|
---|
142 | variants);
|
---|
143 | connect(pNotification, &UINotificationProgressMediumCreate::sigMediumCreated,
|
---|
144 | &uiCommon(), &UICommon::sltHandleMediumCreated);
|
---|
145 | gpNotificationCenter->append(pNotification);
|
---|
146 |
|
---|
147 | /* Positive: */
|
---|
148 | return true;
|
---|
149 | }
|
---|
150 |
|
---|
151 | void UIWizardNewVD::retranslateUi()
|
---|
152 | {
|
---|
153 | UINativeWizard::retranslateUi();
|
---|
154 | setWindowTitle(tr("Create Virtual Hard Disk"));
|
---|
155 | }
|
---|
156 |
|
---|
157 | void UIWizardNewVD::setMediumVariantPageVisibility()
|
---|
158 | {
|
---|
159 | AssertReturnVoid(!m_comMediumFormat.isNull());
|
---|
160 | ULONG uCapabilities = 0;
|
---|
161 | QVector<KMediumFormatCapabilities> capabilities;
|
---|
162 | capabilities = m_comMediumFormat.GetCapabilities();
|
---|
163 | for (int i = 0; i < capabilities.size(); i++)
|
---|
164 | uCapabilities |= capabilities[i];
|
---|
165 |
|
---|
166 | int cTest = 0;
|
---|
167 | if (uCapabilities & KMediumFormatCapabilities_CreateDynamic)
|
---|
168 | ++cTest;
|
---|
169 | if (uCapabilities & KMediumFormatCapabilities_CreateFixed)
|
---|
170 | ++cTest;
|
---|
171 | if (uCapabilities & KMediumFormatCapabilities_CreateSplit2G)
|
---|
172 | ++cTest;
|
---|
173 | setPageVisible(m_iMediumVariantPageIndex, cTest > 1);
|
---|
174 | }
|
---|