VirtualBox

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

Last change on this file since 40870 was 40870, checked in by vboxsync, 13 years ago

FE/Qt: 6123: Rework VirtualBox wizards to unify them at the common architecture required for an expert-mode support.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 4.7 KB
Line 
1/* $Id: UIWizardCloneVD.cpp 40870 2012-04-11 15:44:29Z 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 "VBoxGlobal.h"
31#include "UIMessageCenter.h"
32
33UIWizardCloneVD::UIWizardCloneVD(QWidget *pParent, const CMedium &sourceVirtualDisk)
34 : UIWizard(pParent)
35{
36#ifdef Q_WS_WIN
37 /* Hide window icon: */
38 setWindowIcon(QIcon());
39#endif /* Q_WS_WIN */
40
41 /* Create & add pages: */
42 setPage(Page1, new UIWizardCloneVDPageBasic1(sourceVirtualDisk));
43 setPage(Page2, new UIWizardCloneVDPageBasic2);
44 setPage(Page3, new UIWizardCloneVDPageBasic3);
45 setPage(Page4, new UIWizardCloneVDPageBasic4);
46 setPage(Page5, new UIWizardCloneVDPageBasic5);
47
48 /* Translate wizard: */
49 retranslateUi();
50
51 /* Translate wizard pages: */
52 retranslateAllPages();
53
54#ifndef Q_WS_MAC
55 /* Assign watermark: */
56 assignWatermark(":/vmw_new_harddisk.png");
57#else /* Q_WS_MAC */
58 /* Assign background image: */
59 assignBackground(":/vmw_new_harddisk_bg.png");
60#endif /* Q_WS_MAC */
61
62 /* Resize wizard to 'golden ratio': */
63 resizeToGoldenRatio(UIWizardType_CloneVD);
64}
65
66/* static */
67QString UIWizardCloneVD::fullFormatName(const QString &strBaseFormatName)
68{
69 if (strBaseFormatName == "VDI")
70 return QApplication::translate("UIWizardCloneVD", "&VDI (VirtualBox Disk Image)");
71 else if (strBaseFormatName == "VMDK")
72 return QApplication::translate("UIWizardCloneVD", "V&MDK (Virtual Machine Disk)");
73 else if (strBaseFormatName == "VHD")
74 return QApplication::translate("UIWizardCloneVD", "V&HD (Virtual Hard Disk)");
75 else if (strBaseFormatName == "Parallels")
76 return QApplication::translate("UIWizardCloneVD", "H&DD (Parallels Hard Disk)");
77 else if (strBaseFormatName == "QED")
78 return QApplication::translate("UIWizardCloneVD", "Q&ED (QEMU enhanced disk)");
79 else if (strBaseFormatName == "QCOW")
80 return QApplication::translate("UIWizardCloneVD", "&QCOW (QEMU Copy-On-Write)");
81 return strBaseFormatName;
82}
83
84bool UIWizardCloneVD::copyVirtualDisk()
85{
86 /* Gather attributes: */
87 CMedium sourceVirtualDisk = field("sourceVirtualDisk").value<CMedium>();
88 CMediumFormat mediumFormat = field("mediumFormat").value<CMediumFormat>();
89 qulonglong uVariant = field("mediumVariant").toULongLong();
90 QString strMediumPath = field("mediumPath").toString();
91 qulonglong uSize = field("mediumSize").toULongLong();
92 /* Check attributes: */
93 AssertReturn(!strMediumPath.isNull(), false);
94 AssertReturn(uSize > 0, false);
95
96 /* Get VBox object: */
97 CVirtualBox vbox = vboxGlobal().virtualBox();
98
99 /* Create new virtual-disk: */
100 CMedium virtualDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath);
101 CProgress progress;
102 if (!vbox.isOk())
103 {
104 msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
105 return false;
106 }
107
108 /* Copy existing virtual-disk to the new virtual-disk: */
109 progress = sourceVirtualDisk.CloneTo(virtualDisk, uVariant, CMedium());
110 if (!virtualDisk.isOk())
111 {
112 msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
113 return false;
114 }
115
116 /* Show creation progress: */
117 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this, true);
118 if (progress.GetCanceled())
119 return false;
120 if (!progress.isOk() || progress.GetResultCode() != 0)
121 {
122 msgCenter().cannotCreateHardDiskStorage(this, vbox, strMediumPath, virtualDisk, progress);
123 return false;
124 }
125
126 /* Remember created virtual-disk: */
127 m_virtualDisk = virtualDisk;
128
129 /* Just close the created medium, it is not necessary yet: */
130 m_virtualDisk.Close();
131
132 return true;
133}
134
135void UIWizardCloneVD::retranslateUi()
136{
137 /* Translate wizard: */
138 setWindowTitle(tr("Copy Virtual Disk"));
139 setButtonText(QWizard::FinishButton, tr("Copy"));
140}
141
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