1 | /* $Id: UIWizardNewCloudVMPageExpert.cpp 101563 2023-10-23 23:36:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardNewCloudVMPageExpert 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 <QHeaderView>
|
---|
30 | #include <QListWidget>
|
---|
31 | #include <QPushButton>
|
---|
32 | #include <QTabBar>
|
---|
33 | #include <QVBoxLayout>
|
---|
34 |
|
---|
35 | /* GUI includes: */
|
---|
36 | #include "QIComboBox.h"
|
---|
37 | #include "QIToolButton.h"
|
---|
38 | #include "UICloudNetworkingStuff.h"
|
---|
39 | #include "UIFormEditorWidget.h"
|
---|
40 | #include "UIIconPool.h"
|
---|
41 | #include "UINotificationCenter.h"
|
---|
42 | #include "UIToolBox.h"
|
---|
43 | #include "UIVirtualBoxEventHandler.h"
|
---|
44 | #include "UIVirtualBoxManager.h"
|
---|
45 | #include "UIWizardNewCloudVM.h"
|
---|
46 | #include "UIWizardNewCloudVMPageExpert.h"
|
---|
47 |
|
---|
48 | /* Namespaces: */
|
---|
49 | using namespace UIWizardNewCloudVMSource;
|
---|
50 | using namespace UIWizardNewCloudVMProperties;
|
---|
51 |
|
---|
52 |
|
---|
53 | UIWizardNewCloudVMPageExpert::UIWizardNewCloudVMPageExpert()
|
---|
54 | : m_pToolBox(0)
|
---|
55 | , m_pProviderComboBox(0)
|
---|
56 | , m_pProfileComboBox(0)
|
---|
57 | , m_pProfileToolButton(0)
|
---|
58 | , m_pSourceTabBar(0)
|
---|
59 | , m_pSourceImageList(0)
|
---|
60 | , m_pFormEditor(0)
|
---|
61 | {
|
---|
62 | /* Prepare main layout: */
|
---|
63 | QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
|
---|
64 | if (pLayoutMain)
|
---|
65 | {
|
---|
66 | /* Prepare tool-box: */
|
---|
67 | m_pToolBox = new UIToolBox(this);
|
---|
68 | if (m_pToolBox)
|
---|
69 | {
|
---|
70 | /* Prepare location widget: */
|
---|
71 | QWidget *pWidgetLocation = new QWidget(m_pToolBox);
|
---|
72 | if (pWidgetLocation)
|
---|
73 | {
|
---|
74 | /* Prepare location layout: */
|
---|
75 | QVBoxLayout *pLayoutLocation = new QVBoxLayout(pWidgetLocation);
|
---|
76 | if (pLayoutLocation)
|
---|
77 | {
|
---|
78 | pLayoutLocation->setContentsMargins(0, 0, 0, 0);
|
---|
79 |
|
---|
80 | /* Prepare provider combo-box: */
|
---|
81 | m_pProviderComboBox = new QIComboBox(pWidgetLocation);
|
---|
82 | if (m_pProviderComboBox)
|
---|
83 | pLayoutLocation->addWidget(m_pProviderComboBox);
|
---|
84 |
|
---|
85 | /* Prepare profile layout: */
|
---|
86 | QHBoxLayout *pLayoutProfile = new QHBoxLayout;
|
---|
87 | if (pLayoutProfile)
|
---|
88 | {
|
---|
89 | pLayoutProfile->setContentsMargins(0, 0, 0, 0);
|
---|
90 | pLayoutProfile->setSpacing(1);
|
---|
91 |
|
---|
92 | /* Prepare profile combo-box: */
|
---|
93 | m_pProfileComboBox = new QIComboBox(pWidgetLocation);
|
---|
94 | if (m_pProfileComboBox)
|
---|
95 | pLayoutProfile->addWidget(m_pProfileComboBox);
|
---|
96 |
|
---|
97 | /* Prepare profile tool-button: */
|
---|
98 | m_pProfileToolButton = new QIToolButton(pWidgetLocation);
|
---|
99 | if (m_pProfileToolButton)
|
---|
100 | {
|
---|
101 | m_pProfileToolButton->setIcon(UIIconPool::iconSet(":/cloud_profile_manager_16px.png",
|
---|
102 | ":/cloud_profile_manager_disabled_16px.png"));
|
---|
103 | pLayoutProfile->addWidget(m_pProfileToolButton);
|
---|
104 | }
|
---|
105 |
|
---|
106 | /* Add into layout: */
|
---|
107 | pLayoutLocation->addLayout(pLayoutProfile);
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | /* Add into tool-box: */
|
---|
112 | m_pToolBox->insertPage(0, pWidgetLocation, QString());
|
---|
113 | }
|
---|
114 |
|
---|
115 | /* Prepare source widget: */
|
---|
116 | QWidget *pWidgetSource = new QWidget(m_pToolBox);
|
---|
117 | if (pWidgetSource)
|
---|
118 | {
|
---|
119 | /* Prepare source layout: */
|
---|
120 | QVBoxLayout *pLayoutSource = new QVBoxLayout(pWidgetSource);
|
---|
121 | if (pLayoutSource)
|
---|
122 | {
|
---|
123 | pLayoutSource->setContentsMargins(0, 0, 0, 0);
|
---|
124 | pLayoutSource->setSpacing(0);
|
---|
125 |
|
---|
126 | /* Prepare source tab-bar: */
|
---|
127 | m_pSourceTabBar = new QTabBar(pWidgetSource);
|
---|
128 | if (m_pSourceTabBar)
|
---|
129 | {
|
---|
130 | m_pSourceTabBar->addTab(QString());
|
---|
131 | m_pSourceTabBar->addTab(QString());
|
---|
132 |
|
---|
133 | /* Add into layout: */
|
---|
134 | pLayoutSource->addWidget(m_pSourceTabBar);
|
---|
135 | }
|
---|
136 |
|
---|
137 | /* Prepare source image list: */
|
---|
138 | m_pSourceImageList = new QListWidget(pWidgetSource);
|
---|
139 | if (m_pSourceImageList)
|
---|
140 | {
|
---|
141 | /* We want to have sorting enabled: */
|
---|
142 | m_pSourceImageList->setSortingEnabled(true);
|
---|
143 | /* A bit of look&feel: */
|
---|
144 | m_pSourceImageList->setAlternatingRowColors(true);
|
---|
145 |
|
---|
146 | /* Add into layout: */
|
---|
147 | pLayoutSource->addWidget(m_pSourceImageList);
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | /* Add into tool-box: */
|
---|
152 | m_pToolBox->insertPage(1, pWidgetSource, QString());
|
---|
153 | }
|
---|
154 |
|
---|
155 | /* Prepare settings widget: */
|
---|
156 | QWidget *pWidgetSettings = new QWidget(m_pToolBox);
|
---|
157 | if (pWidgetSettings)
|
---|
158 | {
|
---|
159 | /* Prepare settings layout: */
|
---|
160 | QVBoxLayout *pLayoutSettings = new QVBoxLayout(pWidgetSettings);
|
---|
161 | if (pLayoutSettings)
|
---|
162 | {
|
---|
163 | pLayoutSettings->setContentsMargins(0, 0, 0, 0);
|
---|
164 |
|
---|
165 | /* Prepare form editor widget: */
|
---|
166 | m_pFormEditor = new UIFormEditorWidget(pWidgetSettings);
|
---|
167 | if (m_pFormEditor)
|
---|
168 | {
|
---|
169 | /* Add into layout: */
|
---|
170 | pLayoutSettings->addWidget(m_pFormEditor);
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | /* Add into tool-box: */
|
---|
175 | m_pToolBox->insertPage(2, pWidgetSettings, QString());
|
---|
176 | }
|
---|
177 |
|
---|
178 | /* Add into layout: */
|
---|
179 | pLayoutMain->addWidget(m_pToolBox);
|
---|
180 | }
|
---|
181 | }
|
---|
182 |
|
---|
183 | /* Setup connections: */
|
---|
184 | connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileRegistered,
|
---|
185 | this, &UIWizardNewCloudVMPageExpert::sltHandleProviderComboChange);
|
---|
186 | connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileChanged,
|
---|
187 | this, &UIWizardNewCloudVMPageExpert::sltHandleProviderComboChange);
|
---|
188 | connect(m_pProviderComboBox, &QIComboBox::activated,
|
---|
189 | this, &UIWizardNewCloudVMPageExpert::sltHandleProviderComboChange);
|
---|
190 | connect(m_pProfileComboBox, &QIComboBox::currentIndexChanged,
|
---|
191 | this, &UIWizardNewCloudVMPageExpert::sltHandleProfileComboChange);
|
---|
192 | connect(m_pProfileToolButton, &QIToolButton::clicked,
|
---|
193 | this, &UIWizardNewCloudVMPageExpert::sltHandleProfileButtonClick);
|
---|
194 | connect(m_pSourceTabBar, &QTabBar::currentChanged,
|
---|
195 | this, &UIWizardNewCloudVMPageExpert::sltHandleSourceTabBarChange);
|
---|
196 | connect(m_pSourceImageList, &QListWidget::currentRowChanged,
|
---|
197 | this, &UIWizardNewCloudVMPageExpert::sltHandleSourceImageChange);
|
---|
198 | }
|
---|
199 |
|
---|
200 | UIWizardNewCloudVM *UIWizardNewCloudVMPageExpert::wizard() const
|
---|
201 | {
|
---|
202 | return qobject_cast<UIWizardNewCloudVM*>(UINativeWizardPage::wizard());
|
---|
203 | }
|
---|
204 |
|
---|
205 | void UIWizardNewCloudVMPageExpert::retranslateUi()
|
---|
206 | {
|
---|
207 | /* Translate tool-box: */
|
---|
208 | if (m_pToolBox)
|
---|
209 | {
|
---|
210 | m_pToolBox->setPageTitle(0, UIWizardNewCloudVM::tr("Location"));
|
---|
211 | m_pToolBox->setPageTitle(1, UIWizardNewCloudVM::tr("Source"));
|
---|
212 | m_pToolBox->setPageTitle(2, UIWizardNewCloudVM::tr("Settings"));
|
---|
213 | }
|
---|
214 |
|
---|
215 | /* Translate received values of Location combo-box.
|
---|
216 | * We are enumerating starting from 0 for simplicity: */
|
---|
217 | if (m_pProviderComboBox)
|
---|
218 | for (int i = 0; i < m_pProviderComboBox->count(); ++i)
|
---|
219 | {
|
---|
220 | m_pProviderComboBox->setItemText(i, m_pProviderComboBox->itemData(i, ProviderData_Name).toString());
|
---|
221 | m_pProviderComboBox->setItemData(i, UIWizardNewCloudVM::tr("Create VM for cloud service provider."), Qt::ToolTipRole);
|
---|
222 | }
|
---|
223 |
|
---|
224 | /* Translate source tab-bar: */
|
---|
225 | if (m_pSourceTabBar)
|
---|
226 | {
|
---|
227 | m_pSourceTabBar->setTabText(0, UIWizardNewCloudVM::tr("&Images"));
|
---|
228 | m_pSourceTabBar->setTabText(1, UIWizardNewCloudVM::tr("&Boot Volumes"));
|
---|
229 | }
|
---|
230 |
|
---|
231 | /* Translate profile stuff: */
|
---|
232 | if (m_pProfileToolButton)
|
---|
233 | m_pProfileToolButton->setToolTip(UIWizardNewCloudVM::tr("Open Cloud Profile Manager..."));
|
---|
234 |
|
---|
235 | /* Update tool-tips: */
|
---|
236 | updateComboToolTip(m_pProviderComboBox);
|
---|
237 | }
|
---|
238 |
|
---|
239 | void UIWizardNewCloudVMPageExpert::initializePage()
|
---|
240 | {
|
---|
241 | /* Choose 1st tool to be chosen initially: */
|
---|
242 | m_pToolBox->setCurrentPage(0);
|
---|
243 | /* Make sure form-editor knows notification-center: */
|
---|
244 | m_pFormEditor->setNotificationCenter(wizard()->notificationCenter());
|
---|
245 | /* Populate providers: */
|
---|
246 | populateProviders(m_pProviderComboBox, wizard()->notificationCenter());
|
---|
247 | /* Translate providers: */
|
---|
248 | retranslateUi();
|
---|
249 | /* Make image list focused by default: */
|
---|
250 | m_pSourceImageList->setFocus();
|
---|
251 | /* Fetch it, asynchronously: */
|
---|
252 | QMetaObject::invokeMethod(this, "sltHandleProviderComboChange", Qt::QueuedConnection);
|
---|
253 | }
|
---|
254 |
|
---|
255 | bool UIWizardNewCloudVMPageExpert::isComplete() const
|
---|
256 | {
|
---|
257 | /* Initial result: */
|
---|
258 | bool fResult = true;
|
---|
259 |
|
---|
260 | /* Check cloud settings: */
|
---|
261 | fResult = wizard()->client().isNotNull()
|
---|
262 | && wizard()->vsd().isNotNull();
|
---|
263 |
|
---|
264 | /* Return result: */
|
---|
265 | return fResult;
|
---|
266 | }
|
---|
267 |
|
---|
268 | bool UIWizardNewCloudVMPageExpert::validatePage()
|
---|
269 | {
|
---|
270 | /* Initial result: */
|
---|
271 | bool fResult = true;
|
---|
272 |
|
---|
273 | /* Make sure table has own data committed: */
|
---|
274 | m_pFormEditor->makeSureEditorDataCommitted();
|
---|
275 |
|
---|
276 | /* Check whether we have proper VSD form: */
|
---|
277 | CVirtualSystemDescriptionForm comForm = wizard()->vsdForm();
|
---|
278 | /* Give changed VSD back: */
|
---|
279 | if (comForm.isNotNull())
|
---|
280 | {
|
---|
281 | comForm.GetVirtualSystemDescription();
|
---|
282 | fResult = comForm.isOk();
|
---|
283 | if (!fResult)
|
---|
284 | UINotificationMessage::cannotAcquireVirtualSystemDescriptionFormParameter(comForm, wizard()->notificationCenter());
|
---|
285 | }
|
---|
286 |
|
---|
287 | /* Try to create cloud VM: */
|
---|
288 | if (fResult)
|
---|
289 | {
|
---|
290 | fResult = wizard()->createCloudVM();
|
---|
291 |
|
---|
292 | /* If the final step failed we could try
|
---|
293 | * sugest user more valid form this time: */
|
---|
294 | if (!fResult)
|
---|
295 | {
|
---|
296 | wizard()->setVSDForm(CVirtualSystemDescriptionForm());
|
---|
297 | wizard()->createVSDForm();
|
---|
298 | updatePropertiesTable();
|
---|
299 | emit completeChanged();
|
---|
300 | }
|
---|
301 | }
|
---|
302 |
|
---|
303 | /* Return result: */
|
---|
304 | return fResult;
|
---|
305 | }
|
---|
306 |
|
---|
307 | void UIWizardNewCloudVMPageExpert::sltHandleProviderComboChange()
|
---|
308 | {
|
---|
309 | /* Update combo tool-tip: */
|
---|
310 | updateComboToolTip(m_pProviderComboBox);
|
---|
311 |
|
---|
312 | /* Update wizard fields: */
|
---|
313 | wizard()->setProviderShortName(m_pProviderComboBox->currentData(ProviderData_ShortName).toString());
|
---|
314 |
|
---|
315 | /* Update profiles: */
|
---|
316 | populateProfiles(m_pProfileComboBox, wizard()->notificationCenter(), wizard()->providerShortName(), wizard()->profileName());
|
---|
317 | sltHandleProfileComboChange();
|
---|
318 |
|
---|
319 | /* Notify about changes: */
|
---|
320 | emit completeChanged();
|
---|
321 | }
|
---|
322 |
|
---|
323 | void UIWizardNewCloudVMPageExpert::sltHandleProfileComboChange()
|
---|
324 | {
|
---|
325 | /* Update wizard fields: */
|
---|
326 | wizard()->setProfileName(m_pProfileComboBox->currentData(ProfileData_Name).toString());
|
---|
327 | wizard()->setClient(cloudClientByName(wizard()->providerShortName(), wizard()->profileName(), wizard()->notificationCenter()));
|
---|
328 |
|
---|
329 | /* Update source: */
|
---|
330 | sltHandleSourceTabBarChange();
|
---|
331 |
|
---|
332 | /* Notify about changes: */
|
---|
333 | emit completeChanged();
|
---|
334 | }
|
---|
335 |
|
---|
336 | void UIWizardNewCloudVMPageExpert::sltHandleProfileButtonClick()
|
---|
337 | {
|
---|
338 | if (gpManager)
|
---|
339 | gpManager->openCloudProfileManager();
|
---|
340 | }
|
---|
341 |
|
---|
342 | void UIWizardNewCloudVMPageExpert::sltHandleSourceTabBarChange()
|
---|
343 | {
|
---|
344 | /* Update source type: */
|
---|
345 | wizard()->wizardButton(WizardButtonType_Expert)->setEnabled(false);
|
---|
346 | populateSourceImages(m_pSourceImageList, m_pSourceTabBar, wizard()->notificationCenter(), wizard()->client());
|
---|
347 | wizard()->wizardButton(WizardButtonType_Expert)->setEnabled(true);
|
---|
348 | sltHandleSourceImageChange();
|
---|
349 |
|
---|
350 | /* Notify about changes: */
|
---|
351 | emit completeChanged();
|
---|
352 | }
|
---|
353 |
|
---|
354 | void UIWizardNewCloudVMPageExpert::sltHandleSourceImageChange()
|
---|
355 | {
|
---|
356 | /* Update source image & VSD form: */
|
---|
357 | m_strSourceImageId = currentListWidgetData(m_pSourceImageList);
|
---|
358 | wizard()->setVSD(createVirtualSystemDescription(wizard()->notificationCenter()));
|
---|
359 | populateFormProperties(wizard()->vsd(), wizard(), m_pSourceTabBar, m_strSourceImageId);
|
---|
360 | wizard()->createVSDForm();
|
---|
361 | updatePropertiesTable();
|
---|
362 |
|
---|
363 | /* Notify about changes: */
|
---|
364 | emit completeChanged();
|
---|
365 | }
|
---|
366 |
|
---|
367 | void UIWizardNewCloudVMPageExpert::updatePropertiesTable()
|
---|
368 | {
|
---|
369 | refreshFormPropertiesTable(m_pFormEditor, wizard()->vsdForm());
|
---|
370 | }
|
---|