1 | /* $Id: UIWizardNewVD.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt4 GUI ("VirtualBox"):
|
---|
5 | * UIWizardNewVD class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2013 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Qt includes: */
|
---|
21 | #include <QVariant>
|
---|
22 |
|
---|
23 | /* GUI includes: */
|
---|
24 | #include "UIWizardNewVD.h"
|
---|
25 | #include "UIWizardNewVDPageBasic1.h"
|
---|
26 | #include "UIWizardNewVDPageBasic2.h"
|
---|
27 | #include "UIWizardNewVDPageBasic3.h"
|
---|
28 | #include "UIWizardNewVDPageExpert.h"
|
---|
29 | #include "VBoxGlobal.h"
|
---|
30 | #include "UIMessageCenter.h"
|
---|
31 |
|
---|
32 | /* COM includes: */
|
---|
33 | #include "CMediumFormat.h"
|
---|
34 |
|
---|
35 | UIWizardNewVD::UIWizardNewVD(QWidget *pParent,
|
---|
36 | const QString &strDefaultName, const QString &strDefaultPath,
|
---|
37 | qulonglong uDefaultSize,
|
---|
38 | UIWizardMode mode)
|
---|
39 | : UIWizard(pParent, UIWizardType_NewVD, mode)
|
---|
40 | , m_strDefaultName(strDefaultName)
|
---|
41 | , m_strDefaultPath(strDefaultPath)
|
---|
42 | , m_uDefaultSize(uDefaultSize)
|
---|
43 | {
|
---|
44 | #ifndef Q_WS_MAC
|
---|
45 | /* Assign watermark: */
|
---|
46 | assignWatermark(":/vmw_new_harddisk.png");
|
---|
47 | #else /* Q_WS_MAC */
|
---|
48 | /* Assign background image: */
|
---|
49 | assignBackground(":/vmw_new_harddisk_bg.png");
|
---|
50 | #endif /* Q_WS_MAC */
|
---|
51 | }
|
---|
52 |
|
---|
53 | bool UIWizardNewVD::createVirtualDisk()
|
---|
54 | {
|
---|
55 | /* Gather attributes: */
|
---|
56 | CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>();
|
---|
57 | qulonglong uVariant = field("mediumVariant").toULongLong();
|
---|
58 | QString strMediumPath = field("mediumPath").toString();
|
---|
59 | 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 vbox = vboxGlobal().virtualBox();
|
---|
66 |
|
---|
67 | /* Create new virtual disk: */
|
---|
68 | CMedium virtualDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath);
|
---|
69 | CProgress progress;
|
---|
70 | if (!vbox.isOk())
|
---|
71 | {
|
---|
72 | msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
|
---|
73 | return false;
|
---|
74 | }
|
---|
75 |
|
---|
76 | QVector<KMediumVariant> l_variants(sizeof(qulonglong)*8);
|
---|
77 |
|
---|
78 | for (int i = 0; i < l_variants.size(); ++i)
|
---|
79 | {
|
---|
80 | qulonglong temp = uVariant;
|
---|
81 | temp &= 1<<i;
|
---|
82 | l_variants [i] = (KMediumVariant)temp;
|
---|
83 | }
|
---|
84 |
|
---|
85 | /* Create base storage for the new hard disk: */
|
---|
86 | progress = virtualDisk.CreateBaseStorage(uSize, l_variants);
|
---|
87 |
|
---|
88 | if (!virtualDisk.isOk())
|
---|
89 | {
|
---|
90 | msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
|
---|
91 | return false;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /* Show creation progress: */
|
---|
95 | msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this, true);
|
---|
96 | if (progress.GetCanceled())
|
---|
97 | return false;
|
---|
98 | if (!progress.isOk() || progress.GetResultCode() != 0)
|
---|
99 | {
|
---|
100 | msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
|
---|
101 | return false;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /* Remember created virtual-disk: */
|
---|
105 | m_virtualDisk = virtualDisk;
|
---|
106 |
|
---|
107 | /* Inform everybody there is a new medium: */
|
---|
108 | vboxGlobal().addMedium(UIMedium(m_virtualDisk, UIMediumType_HardDisk, KMediumState_Created));
|
---|
109 |
|
---|
110 | return true;
|
---|
111 | }
|
---|
112 |
|
---|
113 | void UIWizardNewVD::retranslateUi()
|
---|
114 | {
|
---|
115 | /* Call to base-class: */
|
---|
116 | UIWizard::retranslateUi();
|
---|
117 |
|
---|
118 | /* Translate wizard: */
|
---|
119 | setWindowTitle(tr("Create Virtual Hard Drive"));
|
---|
120 | setButtonText(QWizard::FinishButton, tr("Create"));
|
---|
121 | }
|
---|
122 |
|
---|
123 | void UIWizardNewVD::prepare()
|
---|
124 | {
|
---|
125 | /* Create corresponding pages: */
|
---|
126 | switch (mode())
|
---|
127 | {
|
---|
128 | case UIWizardMode_Basic:
|
---|
129 | {
|
---|
130 | setPage(Page1, new UIWizardNewVDPageBasic1);
|
---|
131 | setPage(Page2, new UIWizardNewVDPageBasic2);
|
---|
132 | setPage(Page3, new UIWizardNewVDPageBasic3(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
|
---|
133 | break;
|
---|
134 | }
|
---|
135 | case UIWizardMode_Expert:
|
---|
136 | {
|
---|
137 | setPage(PageExpert, new UIWizardNewVDPageExpert(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
|
---|
138 | break;
|
---|
139 | }
|
---|
140 | default:
|
---|
141 | {
|
---|
142 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
143 | break;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | /* Call to base-class: */
|
---|
147 | UIWizard::prepare();
|
---|
148 | }
|
---|
149 |
|
---|