VirtualBox

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

Last change on this file since 82968 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: UIWizardNewVD.cpp 82968 2020-02-04 10:35:17Z 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
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}
52
53bool 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 = uiCommon().virtualBox();
66
67 /* Create new virtual hard-disk: */
68 CMedium virtualDisk = vbox.CreateMedium(mediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk);
69 if (!vbox.isOk())
70 {
71 msgCenter().cannotCreateHardDiskStorage(vbox, strMediumPath, this);
72 return false;
73 }
74
75 /* Compose medium-variant: */
76 QVector<KMediumVariant> variants(sizeof(qulonglong)*8);
77 for (int i = 0; i < variants.size(); ++i)
78 {
79 qulonglong temp = uVariant;
80 temp &= UINT64_C(1)<<i;
81 variants[i] = (KMediumVariant)temp;
82 }
83
84 /* Create base storage for the new virtual-disk: */
85 CProgress progress = virtualDisk.CreateBaseStorage(uSize, variants);
86 if (!virtualDisk.isOk())
87 {
88 msgCenter().cannotCreateHardDiskStorage(virtualDisk, strMediumPath, this);
89 return false;
90 }
91
92 /* Show creation progress: */
93 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this);
94 if (progress.GetCanceled())
95 return false;
96 if (!progress.isOk() || progress.GetResultCode() != 0)
97 {
98 msgCenter().cannotCreateHardDiskStorage(progress, strMediumPath, this);
99 return false;
100 }
101
102 /* Remember created virtual-disk: */
103 m_virtualDisk = virtualDisk;
104
105 /* Inform UICommon about it: */
106 uiCommon().createMedium(UIMedium(m_virtualDisk, UIMediumDeviceType_HardDisk, KMediumState_Created));
107
108 return true;
109}
110
111void UIWizardNewVD::retranslateUi()
112{
113 /* Call to base-class: */
114 UIWizard::retranslateUi();
115
116 /* Translate wizard: */
117 setWindowTitle(tr("Create Virtual Hard Disk"));
118 setButtonText(QWizard::FinishButton, tr("Create"));
119}
120
121void UIWizardNewVD::prepare()
122{
123 /* Create corresponding pages: */
124 switch (mode())
125 {
126 case WizardMode_Basic:
127 {
128 setPage(Page1, new UIWizardNewVDPageBasic1);
129 setPage(Page2, new UIWizardNewVDPageBasic2);
130 setPage(Page3, new UIWizardNewVDPageBasic3(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
131 break;
132 }
133 case WizardMode_Expert:
134 {
135 setPage(PageExpert, new UIWizardNewVDPageExpert(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
136 break;
137 }
138 default:
139 {
140 AssertMsgFailed(("Invalid mode: %d", mode()));
141 break;
142 }
143 }
144 /* Call to base-class: */
145 UIWizard::prepare();
146}
Note: See TracBrowser for help on using the repository browser.

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