VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevd/UIWizardCloneVD.cpp@ 69198

Last change on this file since 69198 was 69198, checked in by vboxsync, 7 years ago

FE/Qt: bugref:9025: Small cleanup for clone VD wizard.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 4.6 KB
Line 
1/* $Id: UIWizardCloneVD.cpp 69198 2017-10-24 10:41:44Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIWizardCloneVD 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/* GUI includes: */
23# include "UIWizardCloneVD.h"
24# include "UIWizardCloneVDPageBasic1.h"
25# include "UIWizardCloneVDPageBasic2.h"
26# include "UIWizardCloneVDPageBasic3.h"
27# include "UIWizardCloneVDPageBasic4.h"
28# include "UIWizardCloneVDPageExpert.h"
29# include "VBoxGlobal.h"
30# include "UIMessageCenter.h"
31
32/* COM includes: */
33# include "CMediumFormat.h"
34
35#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
36
37
38UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const CMedium &comSourceVirtualDisk)
39 : UIWizard(pParent, WizardType_CloneVD)
40 , m_comSourceVirtualDisk(comSourceVirtualDisk)
41{
42#ifndef VBOX_WS_MAC
43 /* Assign watermark: */
44 assignWatermark(":/vmw_new_harddisk.png");
45#else /* VBOX_WS_MAC */
46 /* Assign background image: */
47 assignBackground(":/vmw_new_harddisk_bg.png");
48#endif /* VBOX_WS_MAC */
49}
50
51bool UIWizardCloneVD::copyVirtualDisk()
52{
53 /* Gather attributes: */
54 CMedium comSourceVirtualDisk = field("sourceVirtualDisk").value<CMedium>();
55 const CMediumFormat comMediumFormat = field("mediumFormat").value<CMediumFormat>();
56 const qulonglong uVariant = field("mediumVariant").toULongLong();
57 const QString strMediumPath = field("mediumPath").toString();
58 const qulonglong uSize = field("mediumSize").toULongLong();
59 /* Check attributes: */
60 AssertReturn(!strMediumPath.isNull(), false);
61 AssertReturn(uSize > 0, false);
62
63 /* Get VBox object: */
64 CVirtualBox comVBox = vboxGlobal().virtualBox();
65
66 /* Create new virtual hard-disk: */
67 CMedium comVirtualDisk = comVBox.CreateMedium(comMediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk);
68 if (!comVBox.isOk())
69 {
70 msgCenter().cannotCreateHardDiskStorage(comVBox, strMediumPath, this);
71 return false;
72 }
73
74 /* Compose medium-variant: */
75 QVector<KMediumVariant> variants(sizeof(qulonglong) * 8);
76 for (int i = 0; i < variants.size(); ++i)
77 {
78 qulonglong temp = uVariant;
79 temp &= Q_UINT64_C(1) << i;
80 variants[i] = (KMediumVariant)temp;
81 }
82
83 /* Copy existing virtual-disk to the new virtual-disk: */
84 CProgress comProgress = comSourceVirtualDisk.CloneTo(comVirtualDisk, variants, CMedium());
85 if (!comSourceVirtualDisk.isOk())
86 {
87 msgCenter().cannotCreateHardDiskStorage(comSourceVirtualDisk, strMediumPath, this);
88 return false;
89 }
90
91 /* Show creation progress: */
92 msgCenter().showModalProgressDialog(comProgress, windowTitle(), ":/progress_media_create_90px.png", this);
93 if (comProgress.GetCanceled())
94 return false;
95 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
96 {
97 msgCenter().cannotCreateHardDiskStorage(comProgress, strMediumPath, this);
98 return false;
99 }
100
101 /* Remember created virtual-disk: */
102 m_comTargetVirtualDisk = comVirtualDisk;
103
104 /* Just close the created medium, it is not necessary yet: */
105 m_comTargetVirtualDisk.Close();
106
107 return true;
108}
109
110void UIWizardCloneVD::retranslateUi()
111{
112 /* Call to base-class: */
113 UIWizard::retranslateUi();
114
115 /* Translate wizard: */
116 setWindowTitle(tr("Copy Virtual Hard Disk"));
117 setButtonText(QWizard::FinishButton, tr("Copy"));
118}
119
120void UIWizardCloneVD::prepare()
121{
122 /* Create corresponding pages: */
123 switch (mode())
124 {
125 case WizardMode_Basic:
126 {
127 setPage(Page1, new UIWizardCloneVDPageBasic1(m_comSourceVirtualDisk));
128 setPage(Page2, new UIWizardCloneVDPageBasic2);
129 setPage(Page3, new UIWizardCloneVDPageBasic3);
130 setPage(Page4, new UIWizardCloneVDPageBasic4);
131 break;
132 }
133 case WizardMode_Expert:
134 {
135 setPage(PageExpert, new UIWizardCloneVDPageExpert(m_comSourceVirtualDisk));
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}
147
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