VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevd/UIWizardCloneVDExpertPage.cpp

Last change on this file was 103957, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in wizard page class hierarchy.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/* $Id: UIWizardCloneVDExpertPage.cpp 103957 2024-03-20 13:41:59Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIWizardCloneVDExpertPage class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QDir>
30#include <QGridLayout>
31
32/* GUI includes: */
33#include "UINotificationCenter.h"
34#include "UIWizardCloneVD.h"
35#include "UIWizardCloneVDExpertPage.h"
36#include "UIWizardDiskEditors.h"
37
38/* COM includes: */
39#include "CSystemProperties.h"
40
41UIWizardCloneVDExpertPage::UIWizardCloneVDExpertPage(KDeviceType enmDeviceType, qulonglong uSourceDiskLogicaSize)
42 : m_pFormatComboBox(0)
43 , m_pVariantWidget(0)
44 , m_pMediumSizePathGroupBox(0)
45 , m_pFormatVariantGroupBox(0)
46 , m_enmDeviceType(enmDeviceType)
47{
48 prepare(enmDeviceType, uSourceDiskLogicaSize);
49}
50
51void UIWizardCloneVDExpertPage::prepare(KDeviceType enmDeviceType, qulonglong uSourceDiskLogicaSize)
52{
53 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
54
55 m_pMediumSizePathGroupBox = new UIMediumSizeAndPathGroupBox(true /* expert mode */, 0 /* parent */, uSourceDiskLogicaSize);
56
57 if (m_pMediumSizePathGroupBox)
58 {
59 pMainLayout->addWidget(m_pMediumSizePathGroupBox);
60 connect(m_pMediumSizePathGroupBox, &UIMediumSizeAndPathGroupBox::sigMediumLocationButtonClicked,
61 this, &UIWizardCloneVDExpertPage::sltSelectLocationButtonClicked);
62 connect(m_pMediumSizePathGroupBox, &UIMediumSizeAndPathGroupBox::sigMediumPathChanged,
63 this, &UIWizardCloneVDExpertPage::sltMediumPathChanged);
64 connect(m_pMediumSizePathGroupBox, &UIMediumSizeAndPathGroupBox::sigMediumSizeChanged,
65 this, &UIWizardCloneVDExpertPage::sltMediumSizeChanged);
66 }
67
68 m_pFormatComboBox = new UIDiskFormatsComboBox(true /* expert mode */, enmDeviceType, 0);
69 if (m_pFormatComboBox)
70 connect(m_pFormatComboBox, &UIDiskFormatsComboBox::sigMediumFormatChanged,
71 this, &UIWizardCloneVDExpertPage::sltMediumFormatChanged);
72
73 m_pVariantWidget = new UIDiskVariantWidget(0);
74 if (m_pVariantWidget)
75 connect(m_pVariantWidget, &UIDiskVariantWidget::sigMediumVariantChanged,
76 this, &UIWizardCloneVDExpertPage::sltMediumVariantChanged);
77
78 m_pFormatVariantGroupBox = new QGroupBox;
79 if (m_pFormatVariantGroupBox)
80 {
81 QHBoxLayout *pFormatVariantLayout = new QHBoxLayout(m_pFormatVariantGroupBox);
82 pFormatVariantLayout->addWidget(m_pFormatComboBox, 0, Qt::AlignTop);
83 pFormatVariantLayout->addWidget(m_pVariantWidget);
84 pMainLayout->addWidget(m_pFormatVariantGroupBox);
85 }
86}
87
88void UIWizardCloneVDExpertPage::sltMediumFormatChanged()
89{
90 if (wizardWindow<UIWizardCloneVD>() && m_pFormatComboBox)
91 wizardWindow<UIWizardCloneVD>()->setMediumFormat(m_pFormatComboBox->mediumFormat());
92 updateDiskWidgetsAfterMediumFormatChange();
93 emit completeChanged();
94}
95
96void UIWizardCloneVDExpertPage::sltSelectLocationButtonClicked()
97{
98 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
99 AssertReturnVoid(pWizard);
100 CMediumFormat comMediumFormat(pWizard->mediumFormat());
101 QString strSelectedPath =
102 UIWizardDiskEditors::openFileDialogForDiskFile(pWizard->mediumPath(), comMediumFormat, pWizard->deviceType(), pWizard);
103
104 if (strSelectedPath.isEmpty())
105 return;
106 QString strMediumPath =
107 UIWizardDiskEditors::appendExtension(strSelectedPath,
108 UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
109 QFileInfo mediumPath(strMediumPath);
110 m_pMediumSizePathGroupBox->setMediumFilePath(QDir::toNativeSeparators(mediumPath.absoluteFilePath()));
111}
112
113void UIWizardCloneVDExpertPage::sltMediumVariantChanged(qulonglong uVariant)
114{
115 if (wizardWindow<UIWizardCloneVD>())
116 wizardWindow<UIWizardCloneVD>()->setMediumVariant(uVariant);
117}
118
119void UIWizardCloneVDExpertPage::sltMediumSizeChanged(qulonglong uSize)
120{
121 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
122 AssertReturnVoid(pWizard);
123 pWizard->setMediumSize(uSize);
124 emit completeChanged();
125}
126
127void UIWizardCloneVDExpertPage::sltMediumPathChanged(const QString &strPath)
128{
129 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
130 AssertReturnVoid(pWizard);
131 QString strMediumPath =
132 UIWizardDiskEditors::appendExtension(strPath,
133 UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
134 pWizard->setMediumPath(strMediumPath);
135 emit completeChanged();
136}
137
138void UIWizardCloneVDExpertPage::sltRetranslateUI()
139{
140 if (m_pFormatVariantGroupBox)
141 m_pFormatVariantGroupBox->setTitle(UIWizardCloneVD::tr("Hard Disk File &Type and Variant"));
142}
143
144void UIWizardCloneVDExpertPage::initializePage()
145{
146 AssertReturnVoid(wizardWindow<UIWizardCloneVD>() && m_pMediumSizePathGroupBox && m_pFormatComboBox && m_pVariantWidget);
147 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
148
149 pWizard->setMediumFormat(m_pFormatComboBox->mediumFormat());
150
151 pWizard->setMediumVariant(m_pVariantWidget->mediumVariant());
152 m_pVariantWidget->updateMediumVariantWidgetsAfterFormatChange(pWizard->mediumFormat());
153
154 /* Initialize medium size widget and wizard's medium size parameter: */
155 m_pMediumSizePathGroupBox->blockSignals(true);
156 m_pMediumSizePathGroupBox->setMediumSize(pWizard->sourceDiskLogicalSize());
157 pWizard->setMediumSize(m_pMediumSizePathGroupBox->mediumSize());
158 QString strExtension = UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType());
159 QString strSourceDiskPath = QDir::toNativeSeparators(QFileInfo(pWizard->sourceDiskFilePath()).absolutePath());
160 /* Disk name without the format extension: */
161 QString strDiskName = QString("%1_%2").arg(QFileInfo(pWizard->sourceDiskName()).completeBaseName()).arg(UIWizardCloneVD::tr("copy"));
162 QString strMediumFilePath =
163 UIWizardDiskEditors::constructMediumFilePath(UIWizardDiskEditors::appendExtension(strDiskName,
164 strExtension), strSourceDiskPath);
165 m_pMediumSizePathGroupBox->setMediumFilePath(strMediumFilePath);
166 pWizard->setMediumPath(strMediumFilePath);
167 m_pMediumSizePathGroupBox->blockSignals(false);
168
169 /* Translate page: */
170 sltRetranslateUI();
171}
172
173bool UIWizardCloneVDExpertPage::isComplete() const
174{
175 bool fResult = true;
176
177 if (m_pFormatComboBox)
178 fResult = m_pFormatComboBox->mediumFormat().isNull();
179 if (m_pVariantWidget)
180 fResult = m_pVariantWidget->isComplete();
181 if (m_pMediumSizePathGroupBox)
182 fResult = m_pMediumSizePathGroupBox->isComplete();
183
184 return fResult;
185}
186
187bool UIWizardCloneVDExpertPage::validatePage()
188{
189 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
190 AssertReturn(pWizard, false);
191
192 QString strMediumPath(pWizard->mediumPath());
193
194 if (QFileInfo(strMediumPath).exists())
195 {
196 UINotificationMessage::cannotOverwriteMediumStorage(strMediumPath, wizard()->notificationCenter());
197 return false;
198 }
199 return pWizard->copyVirtualDisk();
200}
201
202void UIWizardCloneVDExpertPage::updateDiskWidgetsAfterMediumFormatChange()
203{
204 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
205 AssertReturnVoid(pWizard && m_pVariantWidget && m_pMediumSizePathGroupBox && m_pFormatComboBox);
206 const CMediumFormat &comMediumFormat = pWizard->mediumFormat();
207 AssertReturnVoid(!comMediumFormat.isNull());
208
209 m_pVariantWidget->blockSignals(true);
210 m_pVariantWidget->updateMediumVariantWidgetsAfterFormatChange(comMediumFormat);
211 m_pVariantWidget->blockSignals(false);
212
213 m_pMediumSizePathGroupBox->blockSignals(true);
214 m_pMediumSizePathGroupBox->updateMediumPath(comMediumFormat, m_pFormatComboBox->formatExtensions(), m_enmDeviceType);
215 m_pMediumSizePathGroupBox->blockSignals(false);
216 /* Update the wizard parameters explicitly since we blocked th signals: */
217 pWizard->setMediumPath(m_pMediumSizePathGroupBox->mediumFilePath());
218 pWizard->setMediumVariant(m_pVariantWidget->mediumVariant());
219}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use