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