1 | /* $Id: UIWizardCloneVD.cpp 41415 2012-05-23 12:46:34Z 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 "UIWizardCloneVDPageExpert.h"
|
---|
30 | #include "VBoxGlobal.h"
|
---|
31 | #include "UIMessageCenter.h"
|
---|
32 |
|
---|
33 | UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const CMedium &sourceVirtualDisk)
|
---|
34 | : UIWizard(pParent, UIWizardType_CloneVD)
|
---|
35 | , m_sourceVirtualDisk(sourceVirtualDisk)
|
---|
36 | {
|
---|
37 | #ifndef Q_WS_MAC
|
---|
38 | /* Assign watermark: */
|
---|
39 | assignWatermark(":/vmw_new_harddisk.png");
|
---|
40 | #else /* Q_WS_MAC */
|
---|
41 | /* Assign background image: */
|
---|
42 | assignBackground(":/vmw_new_harddisk_bg.png");
|
---|
43 | #endif /* Q_WS_MAC */
|
---|
44 | }
|
---|
45 |
|
---|
46 | bool UIWizardCloneVD::copyVirtualDisk()
|
---|
47 | {
|
---|
48 | /* Gather attributes: */
|
---|
49 | CMedium sourceVirtualDisk = field("sourceVirtualDisk").value<CMedium>();
|
---|
50 | CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>();
|
---|
51 | qulonglong uVariant = field("mediumVariant").toULongLong();
|
---|
52 | QString strMediumPath = field("mediumPath").toString();
|
---|
53 | qulonglong uSize = field("mediumSize").toULongLong();
|
---|
54 | /* Check attributes: */
|
---|
55 | AssertReturn(!strMediumPath.isNull(), false);
|
---|
56 | AssertReturn(uSize > 0, false);
|
---|
57 |
|
---|
58 | /* Get VBox object: */
|
---|
59 | CVirtualBox vbox = vboxGlobal().virtualBox();
|
---|
60 |
|
---|
61 | /* Create new virtual-disk: */
|
---|
62 | CMedium virtualDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath);
|
---|
63 | CProgress progress;
|
---|
64 | if (!vbox.isOk())
|
---|
65 | {
|
---|
66 | msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
|
---|
67 | return false;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /* Copy existing virtual-disk to the new virtual-disk: */
|
---|
71 | progress = sourceVirtualDisk.CloneTo(virtualDisk, uVariant, CMedium());
|
---|
72 | if (!virtualDisk.isOk())
|
---|
73 | {
|
---|
74 | msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
|
---|
75 | return false;
|
---|
76 | }
|
---|
77 |
|
---|
78 | /* Show creation progress: */
|
---|
79 | msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this, true);
|
---|
80 | if (progress.GetCanceled())
|
---|
81 | return false;
|
---|
82 | if (!progress.isOk() || progress.GetResultCode() != 0)
|
---|
83 | {
|
---|
84 | msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
|
---|
85 | return false;
|
---|
86 | }
|
---|
87 |
|
---|
88 | /* Remember created virtual-disk: */
|
---|
89 | m_virtualDisk = virtualDisk;
|
---|
90 |
|
---|
91 | /* Just close the created medium, it is not necessary yet: */
|
---|
92 | m_virtualDisk.Close();
|
---|
93 |
|
---|
94 | return true;
|
---|
95 | }
|
---|
96 |
|
---|
97 | void UIWizardCloneVD::retranslateUi()
|
---|
98 | {
|
---|
99 | /* Call to base-class: */
|
---|
100 | UIWizard::retranslateUi();
|
---|
101 |
|
---|
102 | /* Translate wizard: */
|
---|
103 | setWindowTitle(tr("Copy Virtual Hard Drive"));
|
---|
104 | setButtonText(QWizard::FinishButton, tr("Copy"));
|
---|
105 | }
|
---|
106 |
|
---|
107 | void UIWizardCloneVD::prepare()
|
---|
108 | {
|
---|
109 | /* Create corresponding pages: */
|
---|
110 | switch (mode())
|
---|
111 | {
|
---|
112 | case UIWizardMode_Basic:
|
---|
113 | {
|
---|
114 | setPage(Page1, new UIWizardCloneVDPageBasic1(m_sourceVirtualDisk));
|
---|
115 | setPage(Page2, new UIWizardCloneVDPageBasic2);
|
---|
116 | setPage(Page3, new UIWizardCloneVDPageBasic3);
|
---|
117 | setPage(Page4, new UIWizardCloneVDPageBasic4);
|
---|
118 | break;
|
---|
119 | }
|
---|
120 | case UIWizardMode_Expert:
|
---|
121 | {
|
---|
122 | setPage(PageExpert, new UIWizardCloneVDPageExpert(m_sourceVirtualDisk));
|
---|
123 | break;
|
---|
124 | }
|
---|
125 | default:
|
---|
126 | {
|
---|
127 | AssertMsgFailed(("Invalid mode: %d", mode()));
|
---|
128 | break;
|
---|
129 | }
|
---|
130 | }
|
---|
131 | /* Call to base-class: */
|
---|
132 | UIWizard::prepare();
|
---|
133 | }
|
---|
134 |
|
---|