1 | /* $Id: UIWizardCloneVD.cpp 41021 2012-04-23 11:02:30Z 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 | /* Global includes: */
|
---|
21 | #include <QVariant>
|
---|
22 |
|
---|
23 | /* Local includes: */
|
---|
24 | #include "UIWizardCloneVD.h"
|
---|
25 | #include "UIWizardCloneVDPageBasic1.h"
|
---|
26 | #include "UIWizardCloneVDPageBasic2.h"
|
---|
27 | #include "UIWizardCloneVDPageBasic3.h"
|
---|
28 | #include "UIWizardCloneVDPageBasic4.h"
|
---|
29 | #include "UIWizardCloneVDPageBasic5.h"
|
---|
30 | #include "UIWizardCloneVDPageExpert.h"
|
---|
31 | #include "VBoxGlobal.h"
|
---|
32 | #include "UIMessageCenter.h"
|
---|
33 |
|
---|
34 | UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const CMedium &sourceVirtualDisk)
|
---|
35 | : UIWizard(pParent, UIWizardType_CloneVD)
|
---|
36 | , m_sourceVirtualDisk(sourceVirtualDisk)
|
---|
37 | {
|
---|
38 | #ifndef Q_WS_MAC
|
---|
39 | /* Assign watermark: */
|
---|
40 | assignWatermark(":/vmw_new_harddisk.png");
|
---|
41 | #else /* Q_WS_MAC */
|
---|
42 | /* Assign background image: */
|
---|
43 | assignBackground(":/vmw_new_harddisk_bg.png");
|
---|
44 | #endif /* Q_WS_MAC */
|
---|
45 | }
|
---|
46 |
|
---|
47 | /* static */
|
---|
48 | QString UIWizardCloneVD::fullFormatName(const QString &strBaseFormatName)
|
---|
49 | {
|
---|
50 | if (strBaseFormatName == "VDI")
|
---|
51 | return QApplication::translate("UIWizardCloneVD", "&VDI (VirtualBox Disk Image)");
|
---|
52 | else if (strBaseFormatName == "VMDK")
|
---|
53 | return QApplication::translate("UIWizardCloneVD", "V&MDK (Virtual Machine Disk)");
|
---|
54 | else if (strBaseFormatName == "VHD")
|
---|
55 | return QApplication::translate("UIWizardCloneVD", "V&HD (Virtual Hard Disk)");
|
---|
56 | else if (strBaseFormatName == "Parallels")
|
---|
57 | return QApplication::translate("UIWizardCloneVD", "H&DD (Parallels Hard Disk)");
|
---|
58 | else if (strBaseFormatName == "QED")
|
---|
59 | return QApplication::translate("UIWizardCloneVD", "Q&ED (QEMU enhanced disk)");
|
---|
60 | else if (strBaseFormatName == "QCOW")
|
---|
61 | return QApplication::translate("UIWizardCloneVD", "&QCOW (QEMU Copy-On-Write)");
|
---|
62 | return strBaseFormatName;
|
---|
63 | }
|
---|
64 |
|
---|
65 | bool UIWizardCloneVD::copyVirtualDisk()
|
---|
66 | {
|
---|
67 | /* Gather attributes: */
|
---|
68 | CMedium sourceVirtualDisk = field("sourceVirtualDisk").value<CMedium>();
|
---|
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 | /* Copy existing virtual-disk to the new virtual-disk: */
|
---|
90 | progress = sourceVirtualDisk.CloneTo(virtualDisk, uVariant, CMedium());
|
---|
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 | /* Just close the created medium, it is not necessary yet: */
|
---|
111 | m_virtualDisk.Close();
|
---|
112 |
|
---|
113 | return true;
|
---|
114 | }
|
---|
115 |
|
---|
116 | void UIWizardCloneVD::retranslateUi()
|
---|
117 | {
|
---|
118 | /* Call to base-class: */
|
---|
119 | UIWizard::retranslateUi();
|
---|
120 |
|
---|
121 | /* Translate wizard: */
|
---|
122 | setWindowTitle(tr("Copy Virtual Disk"));
|
---|
123 | setButtonText(QWizard::FinishButton, tr("Copy"));
|
---|
124 | }
|
---|
125 |
|
---|
126 | void UIWizardCloneVD::prepare()
|
---|
127 | {
|
---|
128 | /* Create corresponding pages: */
|
---|
129 | switch (mode())
|
---|
130 | {
|
---|
131 | case UIWizardMode_Basic:
|
---|
132 | {
|
---|
133 | setPage(Page1, new UIWizardCloneVDPageBasic1(m_sourceVirtualDisk));
|
---|
134 | setPage(Page2, new UIWizardCloneVDPageBasic2);
|
---|
135 | setPage(Page3, new UIWizardCloneVDPageBasic3);
|
---|
136 | setPage(Page4, new UIWizardCloneVDPageBasic4);
|
---|
137 | setPage(Page5, new UIWizardCloneVDPageBasic5);
|
---|
138 | break;
|
---|
139 | }
|
---|
140 | case UIWizardMode_Expert:
|
---|
141 | {
|
---|
142 | setPage(PageExpert, new UIWizardCloneVDPageExpert(m_sourceVirtualDisk));
|
---|
143 | break;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | /* Call to base-class: */
|
---|
147 | UIWizard::prepare();
|
---|
148 | }
|
---|
149 |
|
---|