1 | /* $Id: UIWizardNewCloudVMPageSource.cpp 103957 2024-03-20 13:41:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardNewCloudVMPageSource 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 <QGridLayout>
|
---|
30 | #include <QLabel>
|
---|
31 | #include <QListWidget>
|
---|
32 | #include <QPushButton>
|
---|
33 | #include <QTabBar>
|
---|
34 | #include <QVBoxLayout>
|
---|
35 |
|
---|
36 | /* GUI includes: */
|
---|
37 | #include "QIComboBox.h"
|
---|
38 | #include "QIRichTextLabel.h"
|
---|
39 | #include "QIToolButton.h"
|
---|
40 | #include "UICloudNetworkingStuff.h"
|
---|
41 | #include "UIExtraDataManager.h"
|
---|
42 | #include "UIIconPool.h"
|
---|
43 | #include "UINotificationCenter.h"
|
---|
44 | #include "UIVirtualBoxEventHandler.h"
|
---|
45 | #include "UIVirtualBoxManager.h"
|
---|
46 | #include "UIWizardNewCloudVM.h"
|
---|
47 | #include "UIWizardNewCloudVMPageSource.h"
|
---|
48 |
|
---|
49 | /* COM includes: */
|
---|
50 | #include "CStringArray.h"
|
---|
51 |
|
---|
52 | /* Namespaces: */
|
---|
53 | using namespace UIWizardNewCloudVMSource;
|
---|
54 |
|
---|
55 |
|
---|
56 | /*********************************************************************************************************************************
|
---|
57 | * Namespace UIWizardNewCloudVMSource implementation. *
|
---|
58 | *********************************************************************************************************************************/
|
---|
59 |
|
---|
60 | void UIWizardNewCloudVMSource::populateProviders(QIComboBox *pCombo, UINotificationCenter *pCenter)
|
---|
61 | {
|
---|
62 | /* Sanity check: */
|
---|
63 | AssertPtrReturnVoid(pCombo);
|
---|
64 |
|
---|
65 | /* Remember current item data to be able to restore it: */
|
---|
66 | QString strOldData;
|
---|
67 | if (pCombo->currentIndex() != -1)
|
---|
68 | strOldData = pCombo->currentData(ProviderData_ShortName).toString();
|
---|
69 | /* Otherwise "OCI" should be the default one: */
|
---|
70 | else
|
---|
71 | strOldData = "OCI";
|
---|
72 |
|
---|
73 | /* Block signals while updating: */
|
---|
74 | pCombo->blockSignals(true);
|
---|
75 |
|
---|
76 | /* Clear combo initially: */
|
---|
77 | pCombo->clear();
|
---|
78 |
|
---|
79 | /* Iterate through existing providers: */
|
---|
80 | foreach (const CCloudProvider &comProvider, listCloudProviders(pCenter))
|
---|
81 | {
|
---|
82 | /* Skip if we have nothing to populate (file missing?): */
|
---|
83 | if (comProvider.isNull())
|
---|
84 | continue;
|
---|
85 | /* Acquire provider name: */
|
---|
86 | QString strProviderName;
|
---|
87 | if (!cloudProviderName(comProvider, strProviderName, pCenter))
|
---|
88 | continue;
|
---|
89 | /* Acquire provider short name: */
|
---|
90 | QString strProviderShortName;
|
---|
91 | if (!cloudProviderShortName(comProvider, strProviderShortName, pCenter))
|
---|
92 | continue;
|
---|
93 |
|
---|
94 | /* Compose empty item, fill the data: */
|
---|
95 | pCombo->addItem(QString());
|
---|
96 | pCombo->setItemData(pCombo->count() - 1, strProviderName, ProviderData_Name);
|
---|
97 | pCombo->setItemData(pCombo->count() - 1, strProviderShortName, ProviderData_ShortName);
|
---|
98 | }
|
---|
99 |
|
---|
100 | /* Set previous/default item if possible: */
|
---|
101 | int iNewIndex = -1;
|
---|
102 | if ( iNewIndex == -1
|
---|
103 | && !strOldData.isNull())
|
---|
104 | iNewIndex = pCombo->findData(strOldData, ProviderData_ShortName);
|
---|
105 | if ( iNewIndex == -1
|
---|
106 | && pCombo->count() > 0)
|
---|
107 | iNewIndex = 0;
|
---|
108 | if (iNewIndex != -1)
|
---|
109 | pCombo->setCurrentIndex(iNewIndex);
|
---|
110 |
|
---|
111 | /* Unblock signals after update: */
|
---|
112 | pCombo->blockSignals(false);
|
---|
113 | }
|
---|
114 |
|
---|
115 | void UIWizardNewCloudVMSource::populateProfiles(QIComboBox *pCombo,
|
---|
116 | UINotificationCenter *pCenter,
|
---|
117 | const QString &strProviderShortName,
|
---|
118 | const QString &strProfileName)
|
---|
119 | {
|
---|
120 | /* Sanity check: */
|
---|
121 | AssertPtrReturnVoid(pCombo);
|
---|
122 | /* Acquire provider: */
|
---|
123 | CCloudProvider comProvider = cloudProviderByShortName(strProviderShortName, pCenter);
|
---|
124 | AssertReturnVoid(comProvider.isNotNull());
|
---|
125 |
|
---|
126 | /* Remember current item data to be able to restore it: */
|
---|
127 | QString strOldData;
|
---|
128 | if (pCombo->currentIndex() != -1)
|
---|
129 | strOldData = pCombo->currentData(ProfileData_Name).toString();
|
---|
130 | else if (!strProfileName.isEmpty())
|
---|
131 | strOldData = strProfileName;
|
---|
132 |
|
---|
133 | /* Block signals while updating: */
|
---|
134 | pCombo->blockSignals(true);
|
---|
135 |
|
---|
136 | /* Clear combo initially: */
|
---|
137 | pCombo->clear();
|
---|
138 |
|
---|
139 | /* Acquire restricted accounts: */
|
---|
140 | const QStringList restrictedProfiles = gEDataManager->cloudProfileManagerRestrictions();
|
---|
141 |
|
---|
142 | /* Iterate through existing profiles: */
|
---|
143 | QStringList allowedProfileNames;
|
---|
144 | QStringList restrictedProfileNames;
|
---|
145 | foreach (const CCloudProfile &comProfile, listCloudProfiles(comProvider, pCenter))
|
---|
146 | {
|
---|
147 | /* Skip if we have nothing to populate (wtf happened?): */
|
---|
148 | if (comProfile.isNull())
|
---|
149 | continue;
|
---|
150 | /* Acquire current profile name: */
|
---|
151 | QString strCurrentProfileName;
|
---|
152 | if (!cloudProfileName(comProfile, strCurrentProfileName, pCenter))
|
---|
153 | continue;
|
---|
154 |
|
---|
155 | /* Compose full profile name: */
|
---|
156 | const QString strFullProfileName = QString("/%1/%2").arg(strProviderShortName).arg(strCurrentProfileName);
|
---|
157 | /* Append to appropriate list: */
|
---|
158 | if (restrictedProfiles.contains(strFullProfileName))
|
---|
159 | restrictedProfileNames.append(strCurrentProfileName);
|
---|
160 | else
|
---|
161 | allowedProfileNames.append(strCurrentProfileName);
|
---|
162 | }
|
---|
163 |
|
---|
164 | /* Add allowed items: */
|
---|
165 | foreach (const QString &strAllowedProfileName, allowedProfileNames)
|
---|
166 | {
|
---|
167 | /* Compose item, fill it's data: */
|
---|
168 | pCombo->addItem(strAllowedProfileName);
|
---|
169 | pCombo->setItemData(pCombo->count() - 1, strAllowedProfileName, ProfileData_Name);
|
---|
170 | QFont fnt = pCombo->font();
|
---|
171 | fnt.setBold(true);
|
---|
172 | pCombo->setItemData(pCombo->count() - 1, fnt, Qt::FontRole);
|
---|
173 | }
|
---|
174 | /* Add restricted items: */
|
---|
175 | foreach (const QString &strRestrictedProfileName, restrictedProfileNames)
|
---|
176 | {
|
---|
177 | /* Compose item, fill it's data: */
|
---|
178 | pCombo->addItem(strRestrictedProfileName);
|
---|
179 | pCombo->setItemData(pCombo->count() - 1, strRestrictedProfileName, ProfileData_Name);
|
---|
180 | QBrush brsh;
|
---|
181 | brsh.setColor(Qt::gray);
|
---|
182 | pCombo->setItemData(pCombo->count() - 1, brsh, Qt::ForegroundRole);
|
---|
183 | }
|
---|
184 |
|
---|
185 | /* Set previous/default item if possible: */
|
---|
186 | int iNewIndex = -1;
|
---|
187 | if ( iNewIndex == -1
|
---|
188 | && !strOldData.isNull())
|
---|
189 | iNewIndex = pCombo->findData(strOldData, ProfileData_Name);
|
---|
190 | if ( iNewIndex == -1
|
---|
191 | && pCombo->count() > 0)
|
---|
192 | iNewIndex = 0;
|
---|
193 | if (iNewIndex != -1)
|
---|
194 | pCombo->setCurrentIndex(iNewIndex);
|
---|
195 |
|
---|
196 | /* Unblock signals after update: */
|
---|
197 | pCombo->blockSignals(false);
|
---|
198 | }
|
---|
199 |
|
---|
200 | void UIWizardNewCloudVMSource::populateSourceImages(QListWidget *pList,
|
---|
201 | QTabBar *pTabBar,
|
---|
202 | UINotificationCenter *pCenter,
|
---|
203 | const CCloudClient &comClient)
|
---|
204 | {
|
---|
205 | /* Sanity check: */
|
---|
206 | AssertPtrReturnVoid(pList);
|
---|
207 | AssertPtrReturnVoid(pTabBar);
|
---|
208 | AssertReturnVoid(comClient.isNotNull());
|
---|
209 |
|
---|
210 | /* Block signals while updating: */
|
---|
211 | pList->blockSignals(true);
|
---|
212 |
|
---|
213 | /* Clear list initially: */
|
---|
214 | pList->clear();
|
---|
215 |
|
---|
216 | /* Gather source names and ids, depending on current source tab-bar index: */
|
---|
217 | CStringArray comNames;
|
---|
218 | CStringArray comIDs;
|
---|
219 | bool fResult = false;
|
---|
220 | switch (pTabBar->currentIndex())
|
---|
221 | {
|
---|
222 | /* Ask for cloud images, currently we are interested in Available images only: */
|
---|
223 | case 0: fResult = listCloudImages(comClient, comNames, comIDs, pCenter); break;
|
---|
224 | /* Ask for cloud boot-volumes, currently we are interested in Source boot-volumes only: */
|
---|
225 | case 1: fResult = listCloudSourceBootVolumes(comClient, comNames, comIDs, pCenter); break;
|
---|
226 | default: break;
|
---|
227 | }
|
---|
228 | if (fResult)
|
---|
229 | {
|
---|
230 | /* Push acquired names to list rows: */
|
---|
231 | const QVector<QString> names = comNames.GetValues();
|
---|
232 | const QVector<QString> ids = comIDs.GetValues();
|
---|
233 | for (int i = 0; i < names.size(); ++i)
|
---|
234 | {
|
---|
235 | /* Create list item: */
|
---|
236 | QListWidgetItem *pItem = new QListWidgetItem(names.at(i), pList);
|
---|
237 | if (pItem)
|
---|
238 | {
|
---|
239 | pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable);
|
---|
240 | pItem->setData(Qt::UserRole, ids.at(i));
|
---|
241 | }
|
---|
242 | }
|
---|
243 | }
|
---|
244 |
|
---|
245 | /* Choose the 1st one by default if possible: */
|
---|
246 | if (pList->count())
|
---|
247 | pList->setCurrentRow(0);
|
---|
248 |
|
---|
249 | /* Unblock signals after update: */
|
---|
250 | pList->blockSignals(false);
|
---|
251 | }
|
---|
252 |
|
---|
253 | void UIWizardNewCloudVMSource::populateFormProperties(CVirtualSystemDescription comVSD,
|
---|
254 | UIWizardNewCloudVM *pWizard,
|
---|
255 | QTabBar *pTabBar,
|
---|
256 | const QString &strImageId)
|
---|
257 | {
|
---|
258 | /* Sanity check: */
|
---|
259 | AssertReturnVoid(comVSD.isNotNull());
|
---|
260 | AssertPtrReturnVoid(pTabBar);
|
---|
261 |
|
---|
262 | /* Depending on current source tab-bar index: */
|
---|
263 | switch (pTabBar->currentIndex())
|
---|
264 | {
|
---|
265 | /* Add image id to virtual system description: */
|
---|
266 | case 0: comVSD.AddDescription(KVirtualSystemDescriptionType_CloudImageId, strImageId, QString()); break;
|
---|
267 | /* Add boot-volume id to virtual system description: */
|
---|
268 | case 1: comVSD.AddDescription(KVirtualSystemDescriptionType_CloudBootVolumeId, strImageId, QString()); break;
|
---|
269 | default: break;
|
---|
270 | }
|
---|
271 | if (!comVSD.isOk())
|
---|
272 | UINotificationMessage::cannotChangeVirtualSystemDescriptionParameter(comVSD, pWizard->notificationCenter());
|
---|
273 | }
|
---|
274 |
|
---|
275 | void UIWizardNewCloudVMSource::updateComboToolTip(QIComboBox *pCombo)
|
---|
276 | {
|
---|
277 | /* Sanity check: */
|
---|
278 | AssertPtrReturnVoid(pCombo);
|
---|
279 |
|
---|
280 | const int iCurrentIndex = pCombo->currentIndex();
|
---|
281 | if (iCurrentIndex != -1)
|
---|
282 | {
|
---|
283 | const QString strCurrentToolTip = pCombo->itemData(iCurrentIndex, Qt::ToolTipRole).toString();
|
---|
284 | AssertMsg(!strCurrentToolTip.isEmpty(), ("Tool-tip data not found!\n"));
|
---|
285 | pCombo->setToolTip(strCurrentToolTip);
|
---|
286 | }
|
---|
287 | }
|
---|
288 |
|
---|
289 | QString UIWizardNewCloudVMSource::currentListWidgetData(QListWidget *pList)
|
---|
290 | {
|
---|
291 | /* Sanity check: */
|
---|
292 | AssertPtrReturn(pList, QString());
|
---|
293 |
|
---|
294 | QListWidgetItem *pItem = pList->currentItem();
|
---|
295 | return pItem ? pItem->data(Qt::UserRole).toString() : QString();
|
---|
296 | }
|
---|
297 |
|
---|
298 |
|
---|
299 |
|
---|
300 | /*********************************************************************************************************************************
|
---|
301 | * Class UIWizardNewCloudVMPageSource implementation. *
|
---|
302 | *********************************************************************************************************************************/
|
---|
303 |
|
---|
304 | UIWizardNewCloudVMPageSource::UIWizardNewCloudVMPageSource()
|
---|
305 | : m_pLabelMain(0)
|
---|
306 | , m_pProviderLayout(0)
|
---|
307 | , m_pProviderLabel(0)
|
---|
308 | , m_pProviderComboBox(0)
|
---|
309 | , m_pLabelDescription(0)
|
---|
310 | , m_pOptionsLayout(0)
|
---|
311 | , m_pProfileLabel(0)
|
---|
312 | , m_pProfileComboBox(0)
|
---|
313 | , m_pProfileToolButton(0)
|
---|
314 | , m_pSourceImageLabel(0)
|
---|
315 | , m_pSourceTabBar(0)
|
---|
316 | , m_pSourceImageList(0)
|
---|
317 | {
|
---|
318 | /* Prepare main layout: */
|
---|
319 | QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
|
---|
320 | if (pLayoutMain)
|
---|
321 | {
|
---|
322 | /* Prepare main label: */
|
---|
323 | m_pLabelMain = new QIRichTextLabel(this);
|
---|
324 | if (m_pLabelMain)
|
---|
325 | pLayoutMain->addWidget(m_pLabelMain);
|
---|
326 |
|
---|
327 | /* Prepare provider layout: */
|
---|
328 | m_pProviderLayout = new QGridLayout;
|
---|
329 | if (m_pProviderLayout)
|
---|
330 | {
|
---|
331 | m_pProviderLayout->setContentsMargins(0, 0, 0, 0);
|
---|
332 | m_pProviderLayout->setColumnStretch(0, 0);
|
---|
333 | m_pProviderLayout->setColumnStretch(1, 1);
|
---|
334 |
|
---|
335 | /* Prepare provider label: */
|
---|
336 | m_pProviderLabel = new QLabel(this);
|
---|
337 | if (m_pProviderLabel)
|
---|
338 | m_pProviderLayout->addWidget(m_pProviderLabel, 0, 0, Qt::AlignRight);
|
---|
339 |
|
---|
340 | /* Prepare provider combo-box: */
|
---|
341 | m_pProviderComboBox = new QIComboBox(this);
|
---|
342 | if (m_pProviderComboBox)
|
---|
343 | {
|
---|
344 | m_pProviderLabel->setBuddy(m_pProviderComboBox);
|
---|
345 | m_pProviderLayout->addWidget(m_pProviderComboBox, 0, 1);
|
---|
346 | }
|
---|
347 |
|
---|
348 | /* Add into layout: */
|
---|
349 | pLayoutMain->addLayout(m_pProviderLayout);
|
---|
350 | }
|
---|
351 |
|
---|
352 | /* Prepare description label: */
|
---|
353 | m_pLabelDescription = new QIRichTextLabel(this);
|
---|
354 | if (m_pLabelDescription)
|
---|
355 | pLayoutMain->addWidget(m_pLabelDescription);
|
---|
356 |
|
---|
357 | /* Prepare options layout: */
|
---|
358 | m_pOptionsLayout = new QGridLayout;
|
---|
359 | if (m_pOptionsLayout)
|
---|
360 | {
|
---|
361 | m_pOptionsLayout->setContentsMargins(0, 0, 0, 0);
|
---|
362 | m_pOptionsLayout->setColumnStretch(0, 0);
|
---|
363 | m_pOptionsLayout->setColumnStretch(1, 1);
|
---|
364 | m_pOptionsLayout->setRowStretch(1, 0);
|
---|
365 | m_pOptionsLayout->setRowStretch(2, 1);
|
---|
366 |
|
---|
367 | /* Prepare profile label: */
|
---|
368 | m_pProfileLabel = new QLabel(this);
|
---|
369 | if (m_pProfileLabel)
|
---|
370 | m_pOptionsLayout->addWidget(m_pProfileLabel, 0, 0, Qt::AlignRight);
|
---|
371 |
|
---|
372 | /* Prepare profile layout: */
|
---|
373 | QHBoxLayout *pProfileLayout = new QHBoxLayout;
|
---|
374 | if (pProfileLayout)
|
---|
375 | {
|
---|
376 | pProfileLayout->setContentsMargins(0, 0, 0, 0);
|
---|
377 | pProfileLayout->setSpacing(1);
|
---|
378 |
|
---|
379 | /* Prepare profile combo-box: */
|
---|
380 | m_pProfileComboBox = new QIComboBox(this);
|
---|
381 | if (m_pProfileComboBox)
|
---|
382 | {
|
---|
383 | m_pProfileLabel->setBuddy(m_pProfileComboBox);
|
---|
384 | pProfileLayout->addWidget(m_pProfileComboBox);
|
---|
385 | }
|
---|
386 |
|
---|
387 | /* Prepare profile tool-button: */
|
---|
388 | m_pProfileToolButton = new QIToolButton(this);
|
---|
389 | if (m_pProfileToolButton)
|
---|
390 | {
|
---|
391 | m_pProfileToolButton->setIcon(UIIconPool::iconSet(":/cloud_profile_manager_16px.png",
|
---|
392 | ":/cloud_profile_manager_disabled_16px.png"));
|
---|
393 | pProfileLayout->addWidget(m_pProfileToolButton);
|
---|
394 | }
|
---|
395 |
|
---|
396 | /* Add into layout: */
|
---|
397 | m_pOptionsLayout->addLayout(pProfileLayout, 0, 1);
|
---|
398 | }
|
---|
399 |
|
---|
400 | /* Prepare source image label: */
|
---|
401 | m_pSourceImageLabel = new QLabel(this);
|
---|
402 | if (m_pSourceImageLabel)
|
---|
403 | m_pOptionsLayout->addWidget(m_pSourceImageLabel, 1, 0, Qt::AlignRight);
|
---|
404 |
|
---|
405 | /* Prepare source image layout: */
|
---|
406 | QVBoxLayout *pSourceImageLayout = new QVBoxLayout;
|
---|
407 | if (pSourceImageLayout)
|
---|
408 | {
|
---|
409 | pSourceImageLayout->setSpacing(0);
|
---|
410 | pSourceImageLayout->setContentsMargins(0, 0, 0, 0);
|
---|
411 |
|
---|
412 | /* Prepare source tab-bar: */
|
---|
413 | m_pSourceTabBar = new QTabBar(this);
|
---|
414 | if (m_pSourceTabBar)
|
---|
415 | {
|
---|
416 | m_pSourceTabBar->addTab(QString());
|
---|
417 | m_pSourceTabBar->addTab(QString());
|
---|
418 |
|
---|
419 | /* Add into layout: */
|
---|
420 | pSourceImageLayout->addWidget(m_pSourceTabBar);
|
---|
421 | }
|
---|
422 |
|
---|
423 | /* Prepare source image list: */
|
---|
424 | m_pSourceImageList = new QListWidget(this);
|
---|
425 | if (m_pSourceImageList)
|
---|
426 | {
|
---|
427 | m_pSourceImageLabel->setBuddy(m_pSourceImageList);
|
---|
428 | /* Make source image list fit 50 symbols
|
---|
429 | * horizontally and 8 lines vertically: */
|
---|
430 | const QFontMetrics fm(m_pSourceImageList->font());
|
---|
431 | #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)
|
---|
432 | const int iFontWidth = fm.horizontalAdvance('x');
|
---|
433 | #else
|
---|
434 | const int iFontWidth = fm.width('x');
|
---|
435 | #endif
|
---|
436 | const int iTotalWidth = 50 * iFontWidth;
|
---|
437 | const int iFontHeight = fm.height();
|
---|
438 | const int iTotalHeight = 8 * iFontHeight;
|
---|
439 | m_pSourceImageList->setMinimumSize(QSize(iTotalWidth, iTotalHeight));
|
---|
440 | /* We want to have sorting enabled: */
|
---|
441 | m_pSourceImageList->setSortingEnabled(true);
|
---|
442 | /* A bit of look&feel: */
|
---|
443 | m_pSourceImageList->setAlternatingRowColors(true);
|
---|
444 |
|
---|
445 | /* Add into layout: */
|
---|
446 | pSourceImageLayout->addWidget(m_pSourceImageList);
|
---|
447 | }
|
---|
448 |
|
---|
449 | /* Add into layout: */
|
---|
450 | m_pOptionsLayout->addLayout(pSourceImageLayout, 1, 1, 2, 1);
|
---|
451 | }
|
---|
452 |
|
---|
453 | /* Add into layout: */
|
---|
454 | pLayoutMain->addLayout(m_pOptionsLayout);
|
---|
455 | }
|
---|
456 | }
|
---|
457 |
|
---|
458 | /* Setup connections: */
|
---|
459 | connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileRegistered,
|
---|
460 | this, &UIWizardNewCloudVMPageSource::sltHandleProviderComboChange);
|
---|
461 | connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileChanged,
|
---|
462 | this, &UIWizardNewCloudVMPageSource::sltHandleProviderComboChange);
|
---|
463 | connect(m_pProviderComboBox, &QIComboBox::activated,
|
---|
464 | this, &UIWizardNewCloudVMPageSource::sltHandleProviderComboChange);
|
---|
465 | connect(m_pProfileComboBox, &QIComboBox::currentIndexChanged,
|
---|
466 | this, &UIWizardNewCloudVMPageSource::sltHandleProfileComboChange);
|
---|
467 | connect(m_pProfileToolButton, &QIToolButton::clicked,
|
---|
468 | this, &UIWizardNewCloudVMPageSource::sltHandleProfileButtonClick);
|
---|
469 | connect(m_pSourceTabBar, &QTabBar::currentChanged,
|
---|
470 | this, &UIWizardNewCloudVMPageSource::sltHandleSourceTabBarChange);
|
---|
471 | connect(m_pSourceImageList, &QListWidget::currentRowChanged,
|
---|
472 | this, &UIWizardNewCloudVMPageSource::sltHandleSourceImageChange);
|
---|
473 | }
|
---|
474 |
|
---|
475 | UIWizardNewCloudVM *UIWizardNewCloudVMPageSource::wizard() const
|
---|
476 | {
|
---|
477 | return qobject_cast<UIWizardNewCloudVM*>(UINativeWizardPage::wizard());
|
---|
478 | }
|
---|
479 |
|
---|
480 | void UIWizardNewCloudVMPageSource::sltRetranslateUI()
|
---|
481 | {
|
---|
482 | /* Translate page: */
|
---|
483 | setTitle(UIWizardNewCloudVM::tr("Location to create"));
|
---|
484 |
|
---|
485 | /* Translate main label: */
|
---|
486 | m_pLabelMain->setText(UIWizardNewCloudVM::tr("Please choose the location to create cloud virtual machine in. This can "
|
---|
487 | "be one of known cloud service providers below."));
|
---|
488 |
|
---|
489 | /* Translate provider label: */
|
---|
490 | m_pProviderLabel->setText(UIWizardNewCloudVM::tr("&Location:"));
|
---|
491 | /* Translate received values of Location combo-box.
|
---|
492 | * We are enumerating starting from 0 for simplicity: */
|
---|
493 | for (int i = 0; i < m_pProviderComboBox->count(); ++i)
|
---|
494 | {
|
---|
495 | m_pProviderComboBox->setItemText(i, m_pProviderComboBox->itemData(i, ProviderData_Name).toString());
|
---|
496 | m_pProviderComboBox->setItemData(i, UIWizardNewCloudVM::tr("Create VM for cloud service provider."), Qt::ToolTipRole);
|
---|
497 | }
|
---|
498 |
|
---|
499 | /* Translate description label: */
|
---|
500 | m_pLabelDescription->setText(UIWizardNewCloudVM::tr("Please choose one of cloud service profiles you have registered to "
|
---|
501 | "create virtual machine for. Existing images list will be "
|
---|
502 | "updated. To continue, select one of images to create virtual "
|
---|
503 | "machine on the basis of it."));
|
---|
504 |
|
---|
505 | /* Translate profile stuff: */
|
---|
506 | m_pProfileLabel->setText(UIWizardNewCloudVM::tr("&Profile:"));
|
---|
507 | m_pProfileToolButton->setToolTip(UIWizardNewCloudVM::tr("Open Cloud Profile Manager..."));
|
---|
508 | m_pSourceImageLabel->setText(UIWizardNewCloudVM::tr("&Source:"));
|
---|
509 |
|
---|
510 | /* Translate source tab-bar: */
|
---|
511 | m_pSourceTabBar->setTabText(0, UIWizardNewCloudVM::tr("&Images"));
|
---|
512 | m_pSourceTabBar->setTabText(1, UIWizardNewCloudVM::tr("&Boot Volumes"));
|
---|
513 |
|
---|
514 | /* Adjust label widths: */
|
---|
515 | QList<QWidget*> labels;
|
---|
516 | labels << m_pProviderLabel;
|
---|
517 | labels << m_pProfileLabel;
|
---|
518 | labels << m_pSourceImageLabel;
|
---|
519 | int iMaxWidth = 0;
|
---|
520 | foreach (QWidget *pLabel, labels)
|
---|
521 | iMaxWidth = qMax(iMaxWidth, pLabel->minimumSizeHint().width());
|
---|
522 | m_pProviderLayout->setColumnMinimumWidth(0, iMaxWidth);
|
---|
523 | m_pOptionsLayout->setColumnMinimumWidth(0, iMaxWidth);
|
---|
524 |
|
---|
525 | /* Update tool-tips: */
|
---|
526 | updateComboToolTip(m_pProviderComboBox);
|
---|
527 | }
|
---|
528 |
|
---|
529 | void UIWizardNewCloudVMPageSource::initializePage()
|
---|
530 | {
|
---|
531 | /* Populate providers: */
|
---|
532 | populateProviders(m_pProviderComboBox, wizard()->notificationCenter());
|
---|
533 | /* Translate providers: */
|
---|
534 | sltRetranslateUI();
|
---|
535 | /* Fetch it, asynchronously: */
|
---|
536 | QMetaObject::invokeMethod(this, "sltHandleProviderComboChange", Qt::QueuedConnection);
|
---|
537 | /* Make image list focused by default: */
|
---|
538 | m_pSourceImageList->setFocus();
|
---|
539 | }
|
---|
540 |
|
---|
541 | bool UIWizardNewCloudVMPageSource::isComplete() const
|
---|
542 | {
|
---|
543 | /* Initial result: */
|
---|
544 | bool fResult = true;
|
---|
545 |
|
---|
546 | /* Check cloud settings: */
|
---|
547 | fResult = wizard()->client().isNotNull()
|
---|
548 | && !m_strSourceImageId.isNull();
|
---|
549 |
|
---|
550 | /* Return result: */
|
---|
551 | return fResult;
|
---|
552 | }
|
---|
553 |
|
---|
554 | bool UIWizardNewCloudVMPageSource::validatePage()
|
---|
555 | {
|
---|
556 | /* Initial result: */
|
---|
557 | bool fResult = true;
|
---|
558 |
|
---|
559 | /* Populate vsd and form properties: */
|
---|
560 | wizard()->setVSD(createVirtualSystemDescription(wizard()->notificationCenter()));
|
---|
561 | populateFormProperties(wizard()->vsd(), wizard(), m_pSourceTabBar, m_strSourceImageId);
|
---|
562 | wizard()->createVSDForm();
|
---|
563 |
|
---|
564 | /* And make sure they are not NULL: */
|
---|
565 | fResult = wizard()->vsd().isNotNull()
|
---|
566 | && wizard()->vsdForm().isNotNull();
|
---|
567 |
|
---|
568 | /* Return result: */
|
---|
569 | return fResult;
|
---|
570 | }
|
---|
571 |
|
---|
572 | void UIWizardNewCloudVMPageSource::sltHandleProviderComboChange()
|
---|
573 | {
|
---|
574 | /* Update combo tool-tip: */
|
---|
575 | updateComboToolTip(m_pProviderComboBox);
|
---|
576 |
|
---|
577 | /* Update wizard fields: */
|
---|
578 | wizard()->setProviderShortName(m_pProviderComboBox->currentData(ProviderData_ShortName).toString());
|
---|
579 |
|
---|
580 | /* Update profiles: */
|
---|
581 | populateProfiles(m_pProfileComboBox, wizard()->notificationCenter(), wizard()->providerShortName(), wizard()->profileName());
|
---|
582 | sltHandleProfileComboChange();
|
---|
583 |
|
---|
584 | /* Notify about changes: */
|
---|
585 | emit completeChanged();
|
---|
586 | }
|
---|
587 |
|
---|
588 | void UIWizardNewCloudVMPageSource::sltHandleProfileComboChange()
|
---|
589 | {
|
---|
590 | /* Update wizard fields: */
|
---|
591 | wizard()->setProfileName(m_pProfileComboBox->currentData(ProfileData_Name).toString());
|
---|
592 | wizard()->setClient(cloudClientByName(wizard()->providerShortName(), wizard()->profileName(), wizard()->notificationCenter()));
|
---|
593 |
|
---|
594 | /* Update source: */
|
---|
595 | sltHandleSourceTabBarChange();
|
---|
596 |
|
---|
597 | /* Notify about changes: */
|
---|
598 | emit completeChanged();
|
---|
599 | }
|
---|
600 |
|
---|
601 | void UIWizardNewCloudVMPageSource::sltHandleProfileButtonClick()
|
---|
602 | {
|
---|
603 | if (gpManager)
|
---|
604 | gpManager->openCloudProfileManager();
|
---|
605 | }
|
---|
606 |
|
---|
607 | void UIWizardNewCloudVMPageSource::sltHandleSourceTabBarChange()
|
---|
608 | {
|
---|
609 | /* Update source type: */
|
---|
610 | wizard()->wizardButton(WizardButtonType_Expert)->setEnabled(false);
|
---|
611 | populateSourceImages(m_pSourceImageList, m_pSourceTabBar, wizard()->notificationCenter(), wizard()->client());
|
---|
612 | wizard()->wizardButton(WizardButtonType_Expert)->setEnabled(true);
|
---|
613 | sltHandleSourceImageChange();
|
---|
614 |
|
---|
615 | /* Notify about changes: */
|
---|
616 | emit completeChanged();
|
---|
617 | }
|
---|
618 |
|
---|
619 | void UIWizardNewCloudVMPageSource::sltHandleSourceImageChange()
|
---|
620 | {
|
---|
621 | /* Update source image: */
|
---|
622 | m_strSourceImageId = currentListWidgetData(m_pSourceImageList);
|
---|
623 |
|
---|
624 | /* Notify about changes: */
|
---|
625 | emit completeChanged();
|
---|
626 | }
|
---|