1 | /* $Id: UIWizardNewVD.cpp 73586 2018-08-09 13:34:57Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardNewVD 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 | /* Qt includes: */
|
---|
23 | # include <QVariant>
|
---|
24 |
|
---|
25 | /* GUI includes: */
|
---|
26 | # include "VBoxGlobal.h"
|
---|
27 | # include "UIWizardNewVD.h"
|
---|
28 | # include "UIWizardNewVDPageBasic1.h"
|
---|
29 | # include "UIWizardNewVDPageBasic2.h"
|
---|
30 | # include "UIWizardNewVDPageBasic3.h"
|
---|
31 | # include "UIWizardNewVDPageExpert.h"
|
---|
32 | # include "UIMessageCenter.h"
|
---|
33 | # include "UIMedium.h"
|
---|
34 |
|
---|
35 | /* COM includes: */
|
---|
36 | # include "CMediumFormat.h"
|
---|
37 |
|
---|
38 | #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
39 |
|
---|
40 |
|
---|
41 | UIWizardNewVD::UIWizardNewVD(QWidget *pParent,
|
---|
42 | const QString &strDefaultName, const QString &strDefaultPath,
|
---|
43 | qulonglong uDefaultSize,
|
---|
44 | WizardMode mode)
|
---|
45 | : UIWizard(pParent, WizardType_NewVD, mode)
|
---|
46 | , m_strDefaultName(strDefaultName)
|
---|
47 | , m_strDefaultPath(strDefaultPath)
|
---|
48 | , m_uDefaultSize(uDefaultSize)
|
---|
49 | {
|
---|
50 | #ifndef VBOX_WS_MAC
|
---|
51 | /* Assign watermark: */
|
---|
52 | assignWatermark(":/wizard_new_harddisk.png");
|
---|
53 | #else /* VBOX_WS_MAC */
|
---|
54 | /* Assign background image: */
|
---|
55 | assignBackground(":/wizard_new_harddisk_bg.png");
|
---|
56 | #endif /* VBOX_WS_MAC */
|
---|
57 | }
|
---|
58 |
|
---|
59 | bool UIWizardNewVD::createVirtualDisk()
|
---|
60 | {
|
---|
61 | /* Gather attributes: */
|
---|
62 | CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>();
|
---|
63 | qulonglong uVariant = field("mediumVariant").toULongLong();
|
---|
64 | QString strMediumPath = field("mediumPath").toString();
|
---|
65 | qulonglong uSize = field("mediumSize").toULongLong();
|
---|
66 | /* Check attributes: */
|
---|
67 | AssertReturn(!strMediumPath.isNull(), false);
|
---|
68 | AssertReturn(uSize > 0, false);
|
---|
69 |
|
---|
70 | /* Get VBox object: */
|
---|
71 | CVirtualBox vbox = vboxGlobal().virtualBox();
|
---|
72 |
|
---|
73 | /* Create new virtual hard-disk: */
|
---|
74 | CMedium virtualDisk = vbox.CreateMedium(mediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk);
|
---|
75 | if (!vbox.isOk())
|
---|
76 | {
|
---|
77 | msgCenter().cannotCreateHardDiskStorage(vbox, strMediumPath, this);
|
---|
78 | return false;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* Compose medium-variant: */
|
---|
82 | QVector<KMediumVariant> variants(sizeof(qulonglong)*8);
|
---|
83 | for (int i = 0; i < variants.size(); ++i)
|
---|
84 | {
|
---|
85 | qulonglong temp = uVariant;
|
---|
86 | temp &= UINT64_C(1)<<i;
|
---|
87 | variants[i] = (KMediumVariant)temp;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /* Create base storage for the new virtual-disk: */
|
---|
91 | CProgress progress = virtualDisk.CreateBaseStorage(uSize, variants);
|
---|
92 | if (!virtualDisk.isOk())
|
---|
93 | {
|
---|
94 | msgCenter().cannotCreateHardDiskStorage(virtualDisk, strMediumPath, this);
|
---|
95 | return false;
|
---|
96 | }
|
---|
97 |
|
---|
98 | /* Show creation progress: */
|
---|
99 | msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this);
|
---|
100 | if (progress.GetCanceled())
|
---|
101 | return false;
|
---|
102 | if (!progress.isOk() || progress.GetResultCode() != 0)
|
---|
103 | {
|
---|
104 | msgCenter().cannotCreateHardDiskStorage(progress, strMediumPath, this);
|
---|
105 | return false;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /* Remember created virtual-disk: */
|
---|
109 | m_virtualDisk = virtualDisk;
|
---|
110 |
|
---|
111 | /* Inform VBoxGlobal about it: */
|
---|
112 | vboxGlobal().createMedium(UIMedium(m_virtualDisk, UIMediumType_HardDisk, KMediumState_Created));
|
---|
113 |
|
---|
114 | return true;
|
---|
115 | }
|
---|
116 |
|
---|
117 | void UIWizardNewVD::retranslateUi()
|
---|
118 | {
|
---|
119 | /* Call to base-class: */
|
---|
120 | UIWizard::retranslateUi();
|
---|
121 |
|
---|
122 | /* Translate wizard: */
|
---|
123 | setWindowTitle(tr("Create Virtual Hard Disk"));
|
---|
124 | setButtonText(QWizard::FinishButton, tr("Create"));
|
---|
125 | }
|
---|
126 |
|
---|
127 | void UIWizardNewVD::prepare()
|
---|
128 | {
|
---|
129 | /* Create corresponding pages: */
|
---|
130 | switch (mode())
|
---|
131 | {
|
---|
132 | case WizardMode_Basic:
|
---|
133 | {
|
---|
134 | setPage(Page1, new UIWizardNewVDPageBasic1);
|
---|
135 | setPage(Page2, new UIWizardNewVDPageBasic2);
|
---|
136 | setPage(Page3, new UIWizardNewVDPageBasic3(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
|
---|
137 | break;
|
---|
138 | }
|
---|
139 | case WizardMode_Expert:
|
---|
140 | {
|
---|
141 | setPage(PageExpert, new UIWizardNewVDPageExpert(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
|
---|
142 | break;
|
---|
143 | }
|
---|
144 | default:
|
---|
145 | {
|
---|
146 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
147 | break;
|
---|
148 | }
|
---|
149 | }
|
---|
150 | /* Call to base-class: */
|
---|
151 | UIWizard::prepare();
|
---|
152 | }
|
---|