1 | /* $Id: UIWizardCloneVD.cpp 51214 2014-05-08 13:23:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * VBox frontends: Qt4 GUI ("VirtualBox"):
|
---|
5 | * UIWizardCloneVD class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2013 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 |
|
---|
36 | UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const CMedium &sourceVirtualDisk)
|
---|
37 | : UIWizard(pParent, WizardType_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 |
|
---|
49 | bool 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 hard-disk: */
|
---|
65 | CMedium virtualDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath);
|
---|
66 | if (!vbox.isOk())
|
---|
67 | {
|
---|
68 | msgCenter().cannotCreateHardDiskStorage(vbox, strMediumPath, this);
|
---|
69 | return false;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /* Compose medium-variant: */
|
---|
73 | QVector<KMediumVariant> variants(sizeof(qulonglong)*8);
|
---|
74 | for (int i = 0; i < variants.size(); ++i)
|
---|
75 | {
|
---|
76 | qulonglong temp = uVariant;
|
---|
77 | temp &= Q_UINT64_C(1) << i;
|
---|
78 | variants[i] = (KMediumVariant)temp;
|
---|
79 | }
|
---|
80 |
|
---|
81 | /* Copy existing virtual-disk to the new virtual-disk: */
|
---|
82 | CProgress progress = sourceVirtualDisk.CloneTo(virtualDisk, variants, CMedium());
|
---|
83 | if (!sourceVirtualDisk.isOk())
|
---|
84 | {
|
---|
85 | msgCenter().cannotCreateHardDiskStorage(sourceVirtualDisk, strMediumPath, this);
|
---|
86 | return false;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /* Show creation progress: */
|
---|
90 | msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this);
|
---|
91 | if (progress.GetCanceled())
|
---|
92 | return false;
|
---|
93 | if (!progress.isOk() || progress.GetResultCode() != 0)
|
---|
94 | {
|
---|
95 | msgCenter().cannotCreateHardDiskStorage(progress, strMediumPath, this);
|
---|
96 | return false;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /* Remember created virtual-disk: */
|
---|
100 | m_virtualDisk = virtualDisk;
|
---|
101 |
|
---|
102 | /* Just close the created medium, it is not necessary yet: */
|
---|
103 | m_virtualDisk.Close();
|
---|
104 |
|
---|
105 | return true;
|
---|
106 | }
|
---|
107 |
|
---|
108 | void UIWizardCloneVD::retranslateUi()
|
---|
109 | {
|
---|
110 | /* Call to base-class: */
|
---|
111 | UIWizard::retranslateUi();
|
---|
112 |
|
---|
113 | /* Translate wizard: */
|
---|
114 | setWindowTitle(tr("Copy Virtual Hard Drive"));
|
---|
115 | setButtonText(QWizard::FinishButton, tr("Copy"));
|
---|
116 | }
|
---|
117 |
|
---|
118 | void UIWizardCloneVD::prepare()
|
---|
119 | {
|
---|
120 | /* Create corresponding pages: */
|
---|
121 | switch (mode())
|
---|
122 | {
|
---|
123 | case UIWizardMode_Basic:
|
---|
124 | {
|
---|
125 | setPage(Page1, new UIWizardCloneVDPageBasic1(m_sourceVirtualDisk));
|
---|
126 | setPage(Page2, new UIWizardCloneVDPageBasic2);
|
---|
127 | setPage(Page3, new UIWizardCloneVDPageBasic3);
|
---|
128 | setPage(Page4, new UIWizardCloneVDPageBasic4);
|
---|
129 | break;
|
---|
130 | }
|
---|
131 | case UIWizardMode_Expert:
|
---|
132 | {
|
---|
133 | setPage(PageExpert, new UIWizardCloneVDPageExpert(m_sourceVirtualDisk));
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | default:
|
---|
137 | {
|
---|
138 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
139 | break;
|
---|
140 | }
|
---|
141 | }
|
---|
142 | /* Call to base-class: */
|
---|
143 | UIWizard::prepare();
|
---|
144 | }
|
---|
145 |
|
---|