VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevd/UIWizardCloneVDPathSizePage.cpp@ 104158

Last change on this file since 104158 was 103957, checked in by vboxsync, 10 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: 6.1 KB
Line 
1/* $Id: UIWizardCloneVDPathSizePage.cpp 103957 2024-03-20 13:41:59Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIWizardCloneVDPathSizePage 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 <QVBoxLayout>
31
32/* GUI includes: */
33#include "UINotificationCenter.h"
34#include "UIWizardCloneVDPathSizePage.h"
35#include "UIWizardDiskEditors.h"
36#include "UIWizardCloneVD.h"
37
38UIWizardCloneVDPathSizePage::UIWizardCloneVDPathSizePage(qulonglong uSourceDiskLogicaSize)
39 : m_pMediumSizePathGroupBox(0)
40{
41 prepare(uSourceDiskLogicaSize);
42}
43
44void UIWizardCloneVDPathSizePage::prepare(qulonglong uSourceDiskLogicaSize)
45{
46 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
47 m_pMediumSizePathGroupBox = new UIMediumSizeAndPathGroupBox(false /* expert mode */, 0 /* parent */, uSourceDiskLogicaSize);
48 if (m_pMediumSizePathGroupBox)
49 {
50 pMainLayout->addWidget(m_pMediumSizePathGroupBox);
51 connect(m_pMediumSizePathGroupBox, &UIMediumSizeAndPathGroupBox::sigMediumLocationButtonClicked,
52 this, &UIWizardCloneVDPathSizePage::sltSelectLocationButtonClicked);
53 connect(m_pMediumSizePathGroupBox, &UIMediumSizeAndPathGroupBox::sigMediumPathChanged,
54 this, &UIWizardCloneVDPathSizePage::sltMediumPathChanged);
55 connect(m_pMediumSizePathGroupBox, &UIMediumSizeAndPathGroupBox::sigMediumSizeChanged,
56 this, &UIWizardCloneVDPathSizePage::sltMediumSizeChanged);
57 }
58 pMainLayout->addStretch();
59 sltRetranslateUI();
60}
61
62void UIWizardCloneVDPathSizePage::sltRetranslateUI()
63{
64 /* Translate page: */
65 setTitle(UIWizardCloneVD::tr("Location and size of the disk image"));
66}
67
68void UIWizardCloneVDPathSizePage::initializePage()
69{
70 AssertReturnVoid(wizardWindow<UIWizardCloneVD>() && m_pMediumSizePathGroupBox);
71 /* Translate page: */
72 sltRetranslateUI();
73 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
74 m_pMediumSizePathGroupBox->blockSignals(true);
75
76 /* Initialize medium size widget and wizard's medium size parameter: */
77 if (!m_userModifiedParameters.contains("MediumSize"))
78 {
79 m_pMediumSizePathGroupBox->setMediumSize(pWizard->sourceDiskLogicalSize());
80 pWizard->setMediumSize(m_pMediumSizePathGroupBox->mediumSize());
81 }
82
83 if (!m_userModifiedParameters.contains("MediumPath"))
84 {
85 QString strExtension = UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType());
86 QString strSourceDiskPath = QDir::toNativeSeparators(QFileInfo(pWizard->sourceDiskFilePath()).absolutePath());
87 /* Disk name without the format extension: */
88 QString strDiskName = QString("%1_%2").arg(QFileInfo(pWizard->sourceDiskName()).completeBaseName()).arg(UIWizardCloneVD::tr("copy"));
89
90 QString strMediumFilePath =
91 UIWizardDiskEditors::constructMediumFilePath(UIWizardDiskEditors::appendExtension(strDiskName,
92 strExtension), strSourceDiskPath);
93 m_pMediumSizePathGroupBox->setMediumFilePath(strMediumFilePath);
94 pWizard->setMediumPath(strMediumFilePath);
95 }
96 m_pMediumSizePathGroupBox->blockSignals(false);
97}
98
99bool UIWizardCloneVDPathSizePage::isComplete() const
100{
101 AssertReturn(m_pMediumSizePathGroupBox, false);
102 return m_pMediumSizePathGroupBox->isComplete();
103}
104
105bool UIWizardCloneVDPathSizePage::validatePage()
106{
107 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
108 AssertReturn(pWizard, false);
109 /* Make sure such file doesn't exists already: */
110 QString strMediumPath(pWizard->mediumPath());
111 if (QFileInfo(strMediumPath).exists())
112 {
113 UINotificationMessage::cannotOverwriteMediumStorage(strMediumPath, wizard()->notificationCenter());
114 return false;
115 }
116 return pWizard->copyVirtualDisk();
117}
118
119void UIWizardCloneVDPathSizePage::sltSelectLocationButtonClicked()
120{
121 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
122 AssertReturnVoid(pWizard);
123 CMediumFormat comMediumFormat(pWizard->mediumFormat());
124 QString strSelectedPath =
125 UIWizardDiskEditors::openFileDialogForDiskFile(pWizard->mediumPath(), comMediumFormat, pWizard->deviceType(), pWizard);
126
127 if (strSelectedPath.isEmpty())
128 return;
129 QString strMediumPath =
130 UIWizardDiskEditors::appendExtension(strSelectedPath,
131 UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
132 QFileInfo mediumPath(strMediumPath);
133 m_pMediumSizePathGroupBox->setMediumFilePath(QDir::toNativeSeparators(mediumPath.absoluteFilePath()));
134}
135
136void UIWizardCloneVDPathSizePage::sltMediumPathChanged(const QString &strPath)
137{
138 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
139 AssertReturnVoid(pWizard);
140 m_userModifiedParameters << "MediumPath";
141 QString strMediumPath =
142 UIWizardDiskEditors::appendExtension(strPath,
143 UIWizardDiskEditors::defaultExtension(pWizard->mediumFormat(), pWizard->deviceType()));
144 pWizard->setMediumPath(strMediumPath);
145 emit completeChanged();
146}
147
148void UIWizardCloneVDPathSizePage::sltMediumSizeChanged(qulonglong uSize)
149{
150 UIWizardCloneVD *pWizard = wizardWindow<UIWizardCloneVD>();
151 AssertReturnVoid(pWizard);
152 m_userModifiedParameters << "MediumSize";
153 pWizard->setMediumSize(uSize);
154 emit completeChanged();
155}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette