VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageSettings.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: 10.5 KB
Line 
1/* $Id: UIWizardExportAppPageSettings.cpp 103957 2024-03-20 13:41:59Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIWizardExportAppPageSettings class implementation.
4 */
5
6/*
7 * Copyright (C) 2009-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 <QStackedWidget>
30#include <QVBoxLayout>
31
32/* GUI includes: */
33#include "QIRichTextLabel.h"
34#include "UIApplianceExportEditorWidget.h"
35#include "UIFormEditorWidget.h"
36#include "UINotificationCenter.h"
37#include "UIWizardExportApp.h"
38#include "UIWizardExportAppPageSettings.h"
39
40/* COM includes: */
41#include "CMachine.h"
42#include "CVirtualSystemDescriptionForm.h"
43
44/* Namespaces: */
45using namespace UIWizardExportAppSettings;
46
47
48/*********************************************************************************************************************************
49* Class UIWizardExportAppSettings implementation. *
50*********************************************************************************************************************************/
51
52void UIWizardExportAppSettings::refreshStackedWidget(QStackedWidget *pStackedWidget,
53 bool fIsFormatCloudOne)
54{
55 /* Update stack appearance according to chosen format: */
56 pStackedWidget->setCurrentIndex((int)fIsFormatCloudOne);
57}
58
59void UIWizardExportAppSettings::refreshApplianceSettingsWidget(UIApplianceExportEditorWidget *pApplianceWidget,
60 const CAppliance &comAppliance,
61 bool fIsFormatCloudOne)
62{
63 /* Nothing for cloud case? */
64 if (fIsFormatCloudOne)
65 return;
66
67 /* Sanity check: */
68 AssertReturnVoid(comAppliance.isNotNull());
69
70 /* Make sure the settings widget get the new appliance: */
71 pApplianceWidget->setAppliance(comAppliance);
72}
73
74void UIWizardExportAppSettings::refreshFormPropertiesTable(UIFormEditorWidget *pFormEditor,
75 const CVirtualSystemDescriptionForm &comVsdForm,
76 bool fIsFormatCloudOne)
77{
78 /* Nothing for local case? */
79 if (!fIsFormatCloudOne)
80 return;
81
82 /* Sanity check: */
83 AssertReturnVoid(comVsdForm.isNotNull());
84
85 /* Make sure the properties table get the new description form: */
86 pFormEditor->setVirtualSystemDescriptionForm(comVsdForm);
87}
88
89
90/*********************************************************************************************************************************
91* Class UIWizardExportAppPageSettings implementation. *
92*********************************************************************************************************************************/
93
94UIWizardExportAppPageSettings::UIWizardExportAppPageSettings()
95 : m_pLabel(0)
96 , m_pSettingsWidget2(0)
97 , m_pApplianceWidget(0)
98 , m_pFormEditor(0)
99 , m_fLaunching(false)
100{
101 /* Create main layout: */
102 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
103 if (pMainLayout)
104 {
105 /* Create label: */
106 m_pLabel = new QIRichTextLabel(this);
107 if (m_pLabel)
108 pMainLayout->addWidget(m_pLabel);
109
110 /* Create settings widget 2: */
111 m_pSettingsWidget2 = new QStackedWidget(this);
112 if (m_pSettingsWidget2)
113 {
114 /* Create appliance widget container: */
115 QWidget *pApplianceWidgetCnt = new QWidget(this);
116 if (pApplianceWidgetCnt)
117 {
118 /* Create appliance widget layout: */
119 QVBoxLayout *pApplianceWidgetLayout = new QVBoxLayout(pApplianceWidgetCnt);
120 if (pApplianceWidgetLayout)
121 {
122 pApplianceWidgetLayout->setContentsMargins(0, 0, 0, 0);
123
124 /* Create appliance widget: */
125 m_pApplianceWidget = new UIApplianceExportEditorWidget(pApplianceWidgetCnt);
126 if (m_pApplianceWidget)
127 {
128 m_pApplianceWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
129 pApplianceWidgetLayout->addWidget(m_pApplianceWidget);
130 }
131 }
132
133 /* Add into layout: */
134 m_pSettingsWidget2->addWidget(pApplianceWidgetCnt);
135 }
136
137 /* Create form editor container: */
138 QWidget *pFormEditorCnt = new QWidget(this);
139 if (pFormEditorCnt)
140 {
141 /* Create form editor layout: */
142 QVBoxLayout *pFormEditorLayout = new QVBoxLayout(pFormEditorCnt);
143 if (pFormEditorLayout)
144 {
145 pFormEditorLayout->setContentsMargins(0, 0, 0, 0);
146
147 /* Create form editor widget: */
148 m_pFormEditor = new UIFormEditorWidget(pFormEditorCnt);
149 if (m_pFormEditor)
150 pFormEditorLayout->addWidget(m_pFormEditor);
151 }
152
153 /* Add into layout: */
154 m_pSettingsWidget2->addWidget(pFormEditorCnt);
155 }
156
157 /* Add into layout: */
158 pMainLayout->addWidget(m_pSettingsWidget2);
159 }
160 }
161}
162
163UIWizardExportApp *UIWizardExportAppPageSettings::wizard() const
164{
165 return qobject_cast<UIWizardExportApp*>(UINativeWizardPage::wizard());
166}
167
168void UIWizardExportAppPageSettings::sltRetranslateUI()
169{
170 /* Translate page: */
171 setTitle(UIWizardExportApp::tr("Appliance settings"));
172
173 /* Translate label: */
174 if (wizard()->isFormatCloudOne())
175 m_pLabel->setText(UIWizardExportApp::tr("This is the descriptive information which will be used to determine settings "
176 "for a cloud storage your VM being exported to. You can change it by double "
177 "clicking on individual lines."));
178 else
179 m_pLabel->setText(UIWizardExportApp::tr("This is the descriptive information which will be added to the virtual "
180 "appliance. You can change it by double clicking on individual lines."));
181}
182
183void UIWizardExportAppPageSettings::initializePage()
184{
185 /* Make sure form-editor knows notification-center: */
186 m_pFormEditor->setNotificationCenter(wizard()->notificationCenter());
187 /* Translate page: */
188 sltRetranslateUI();
189
190 /* Refresh settings widget state: */
191 refreshStackedWidget(m_pSettingsWidget2, wizard()->isFormatCloudOne());
192 /* Refresh corresponding widgets: */
193 refreshApplianceSettingsWidget(m_pApplianceWidget, wizard()->localAppliance(), wizard()->isFormatCloudOne());
194 refreshFormPropertiesTable(m_pFormEditor, wizard()->vsdExportForm(), wizard()->isFormatCloudOne());
195
196 /* Choose initially focused widget: */
197 if (wizard()->isFormatCloudOne())
198 m_pFormEditor->setFocus();
199 else
200 m_pApplianceWidget->setFocus();
201}
202
203bool UIWizardExportAppPageSettings::validatePage()
204{
205 /* Initial result: */
206 bool fResult = true;
207
208 /* Check whether there was cloud target selected: */
209 if (wizard()->isFormatCloudOne())
210 {
211 /* Make sure table has own data committed: */
212 m_pFormEditor->makeSureEditorDataCommitted();
213
214 /* Init VSD form: */
215 CVirtualSystemDescriptionForm comForm;
216 /* Check whether we have proper VSD form: */
217 if (!m_fLaunching)
218 {
219 /* We are going to upload image: */
220 comForm = wizard()->vsdExportForm();
221 fResult = comForm.isNotNull();
222 }
223 else
224 {
225 /* We are going to launch VM: */
226 comForm = wizard()->vsdLaunchForm();
227 fResult = comForm.isNotNull();
228 }
229 /* Give changed VSD back: */
230 if (fResult)
231 {
232 comForm.GetVirtualSystemDescription();
233 fResult = comForm.isOk();
234 if (!fResult)
235 UINotificationMessage::cannotAcquireVirtualSystemDescriptionFormParameter(comForm, wizard()->notificationCenter());
236 }
237
238 /* Final stage? */
239 if (fResult)
240 {
241 if (!m_fLaunching)
242 {
243 /* For modes other than AskThenExport, try to export appliance first: */
244 if (wizard()->cloudExportMode() != CloudExportMode_AskThenExport)
245 fResult = wizard()->exportAppliance();
246
247 /* For modes other than DoNotAsk, switch from uploading image to launching VM: */
248 if ( fResult
249 && wizard()->cloudExportMode() != CloudExportMode_DoNotAsk)
250 {
251 /* Invert flags: */
252 fResult = false;
253 m_fLaunching = true;
254
255 /* Disable wizard buttons: */
256 wizard()->disableButtons();
257
258 /* Refresh corresponding widgets: */
259 wizard()->createVsdLaunchForm();
260 refreshFormPropertiesTable(m_pFormEditor, wizard()->vsdLaunchForm(), wizard()->isFormatCloudOne());
261 }
262 }
263 else
264 {
265 /* For AskThenExport mode, try to export appliance in the end: */
266 if (wizard()->cloudExportMode() == CloudExportMode_AskThenExport)
267 fResult = wizard()->exportAppliance();
268
269 /* Try to create cloud VM: */
270 if (fResult)
271 fResult = wizard()->createCloudVM();
272 }
273 }
274 }
275 /* Otherwise if there was local target selected: */
276 else
277 {
278 /* Prepare export: */
279 m_pApplianceWidget->prepareExport();
280
281 /* Try to export appliance: */
282 if (fResult)
283 fResult = wizard()->exportAppliance();
284 }
285
286 /* Return result: */
287 return fResult;
288}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use