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