VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVD.cpp@ 87859

Last change on this file since 87859 was 87859, checked in by vboxsync, 4 years ago

FE/Qt: bugref:9950. Further refactoring

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette