VirtualBox

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

Last change on this file since 44376 was 44376, checked in by vboxsync, 12 years ago

The changes inside loops where enumeration MediumVariant is converted. For correct work under both systems Windows and Linux because enumeration is defined differently on these systems.

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