VirtualBox

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

Last change on this file since 41021 was 41021, checked in by vboxsync, 13 years ago

FE/Qt: 6123: Initial implementation of expert-mode for VirtualBox wizards.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 5.0 KB
Line 
1/* $Id: UIWizardNewVD.cpp 41021 2012-04-23 11:02:30Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt4 GUI ("VirtualBox"):
5 * UIWizardNewVD class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2012 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/* Global includes: */
21#include <QVariant>
22
23/* Local includes: */
24#include "UIWizardNewVD.h"
25#include "UIWizardNewVDPageBasic1.h"
26#include "UIWizardNewVDPageBasic2.h"
27#include "UIWizardNewVDPageBasic3.h"
28#include "UIWizardNewVDPageBasic4.h"
29#include "UIWizardNewVDPageExpert.h"
30#include "VBoxGlobal.h"
31#include "UIMessageCenter.h"
32
33UIWizardNewVD::UIWizardNewVD(QWidget *pParent, const QString &strDefaultName, const QString &strDefaultPath, qulonglong uDefaultSize)
34 : UIWizard(pParent, UIWizardType_NewVD)
35 , m_strDefaultName(strDefaultName)
36 , m_strDefaultPath(strDefaultPath)
37 , m_uDefaultSize(uDefaultSize)
38{
39#ifndef Q_WS_MAC
40 /* Assign watermark: */
41 assignWatermark(":/vmw_new_harddisk.png");
42#else /* Q_WS_MAC */
43 /* Assign background image: */
44 assignBackground(":/vmw_new_harddisk_bg.png");
45#endif /* Q_WS_MAC */
46}
47
48/* static */
49QString UIWizardNewVD::fullFormatName(const QString &strBaseFormatName)
50{
51 if (strBaseFormatName == "VDI")
52 return QApplication::translate("UIWizardNewVD", "&VDI (VirtualBox Disk Image)");
53 else if (strBaseFormatName == "VMDK")
54 return QApplication::translate("UIWizardNewVD", "V&MDK (Virtual Machine Disk)");
55 else if (strBaseFormatName == "VHD")
56 return QApplication::translate("UIWizardNewVD", "V&HD (Virtual Hard Disk)");
57 else if (strBaseFormatName == "Parallels")
58 return QApplication::translate("UIWizardNewVD", "H&DD (Parallels Hard Disk)");
59 else if (strBaseFormatName == "QED")
60 return QApplication::translate("UIWizardNewVD", "Q&ED (QEMU enhanced disk)");
61 else if (strBaseFormatName == "QCOW")
62 return QApplication::translate("UIWizardNewVD", "&QCOW (QEMU Copy-On-Write)");
63 return strBaseFormatName;
64}
65
66bool UIWizardNewVD::createVirtualDisk()
67{
68 /* Gather attributes: */
69 CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>();
70 qulonglong uVariant = field("mediumVariant").toULongLong();
71 QString strMediumPath = field("mediumPath").toString();
72 qulonglong uSize = field("mediumSize").toULongLong();
73 /* Check attributes: */
74 AssertReturn(!strMediumPath.isNull(), false);
75 AssertReturn(uSize > 0, false);
76
77 /* Get vbox object: */
78 CVirtualBox vbox = vboxGlobal().virtualBox();
79
80 /* Create new virtual disk: */
81 CMedium virtualDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath);
82 CProgress progress;
83 if (!vbox.isOk())
84 {
85 msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
86 return false;
87 }
88
89 /* Create base storage for the new hard disk: */
90 progress = virtualDisk.CreateBaseStorage(uSize, uVariant);
91 if (!virtualDisk.isOk())
92 {
93 msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
94 return false;
95 }
96
97 /* Show creation progress: */
98 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this, true);
99 if (progress.GetCanceled())
100 return false;
101 if (!progress.isOk() || progress.GetResultCode() != 0)
102 {
103 msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
104 return false;
105 }
106
107 /* Remember created virtual-disk: */
108 m_virtualDisk = virtualDisk;
109
110 /* Inform everybody there is a new medium: */
111 vboxGlobal().addMedium(VBoxMedium(m_virtualDisk, VBoxDefs::MediumType_HardDisk, KMediumState_Created));
112
113 return true;
114}
115
116void UIWizardNewVD::retranslateUi()
117{
118 /* Call to base-class: */
119 UIWizard::retranslateUi();
120
121 /* Translate wizard: */
122 setWindowTitle(tr("Create New Virtual Disk"));
123 setButtonText(QWizard::FinishButton, tr("Create"));
124}
125
126void UIWizardNewVD::prepare()
127{
128 /* Create corresponding pages: */
129 switch (mode())
130 {
131 case UIWizardMode_Basic:
132 {
133 setPage(Page1, new UIWizardNewVDPageBasic1);
134 setPage(Page2, new UIWizardNewVDPageBasic2);
135 setPage(Page3, new UIWizardNewVDPageBasic3(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
136 setPage(Page4, new UIWizardNewVDPageBasic4);
137 break;
138 }
139 case UIWizardMode_Expert:
140 {
141 setPage(PageExpert, new UIWizardNewVDPageExpert(m_strDefaultName, m_strDefaultPath, m_uDefaultSize));
142 break;
143 }
144 }
145 /* Call to base-class: */
146 UIWizard::prepare();
147}
148
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