1 | /* $Id: UIWizardAddCloudVMPageExpert.cpp 101563 2023-10-23 23:36:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIWizardAddCloudVMPageExpert 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 <QHBoxLayout>
|
---|
30 | #include <QHeaderView>
|
---|
31 | #include <QListWidget>
|
---|
32 | #include <QPushButton>
|
---|
33 | #include <QTableWidget>
|
---|
34 | #include <QVBoxLayout>
|
---|
35 |
|
---|
36 | /* GUI includes: */
|
---|
37 | #include "QIComboBox.h"
|
---|
38 | #include "QIToolButton.h"
|
---|
39 | #include "UICloudNetworkingStuff.h"
|
---|
40 | #include "UIIconPool.h"
|
---|
41 | #include "UIToolBox.h"
|
---|
42 | #include "UIVirtualBoxEventHandler.h"
|
---|
43 | #include "UIVirtualBoxManager.h"
|
---|
44 | #include "UIWizardAddCloudVM.h"
|
---|
45 | #include "UIWizardAddCloudVMPageExpert.h"
|
---|
46 |
|
---|
47 | /* Namespaces: */
|
---|
48 | using namespace UIWizardAddCloudVMSource;
|
---|
49 |
|
---|
50 |
|
---|
51 | UIWizardAddCloudVMPageExpert::UIWizardAddCloudVMPageExpert()
|
---|
52 | : m_pToolBox(0)
|
---|
53 | , m_pProviderLabel(0)
|
---|
54 | , m_pProviderComboBox(0)
|
---|
55 | , m_pProfileLabel(0)
|
---|
56 | , m_pProfileComboBox(0)
|
---|
57 | , m_pProfileToolButton(0)
|
---|
58 | , m_pSourceInstanceLabel(0)
|
---|
59 | , m_pSourceInstanceList(0)
|
---|
60 | {
|
---|
61 | /* Prepare main layout: */
|
---|
62 | QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
|
---|
63 | if (pLayoutMain)
|
---|
64 | {
|
---|
65 | /* Prepare tool-box: */
|
---|
66 | m_pToolBox = new UIToolBox(this);
|
---|
67 | if (m_pToolBox)
|
---|
68 | {
|
---|
69 | /* Prepare location widget: */
|
---|
70 | QWidget *pWidgetLocation = new QWidget(m_pToolBox);
|
---|
71 | if (pWidgetLocation)
|
---|
72 | {
|
---|
73 | /* Prepare location layout: */
|
---|
74 | QVBoxLayout *pLayoutLocation = new QVBoxLayout(pWidgetLocation);
|
---|
75 | if (pLayoutLocation)
|
---|
76 | {
|
---|
77 | pLayoutLocation->setContentsMargins(0, 0, 0, 0);
|
---|
78 |
|
---|
79 | /* Prepare provider combo-box: */
|
---|
80 | m_pProviderComboBox = new QIComboBox(pWidgetLocation);
|
---|
81 | if (m_pProviderComboBox)
|
---|
82 | pLayoutLocation->addWidget(m_pProviderComboBox);
|
---|
83 |
|
---|
84 | /* Prepare profile layout: */
|
---|
85 | QHBoxLayout *pLayoutProfile = new QHBoxLayout;
|
---|
86 | if (pLayoutProfile)
|
---|
87 | {
|
---|
88 | pLayoutProfile->setContentsMargins(0, 0, 0, 0);
|
---|
89 | pLayoutProfile->setSpacing(1);
|
---|
90 |
|
---|
91 | /* Prepare profile combo-box: */
|
---|
92 | m_pProfileComboBox = new QIComboBox(pWidgetLocation);
|
---|
93 | if (m_pProfileComboBox)
|
---|
94 | pLayoutProfile->addWidget(m_pProfileComboBox);
|
---|
95 |
|
---|
96 | /* Prepare profile tool-button: */
|
---|
97 | m_pProfileToolButton = new QIToolButton(pWidgetLocation);
|
---|
98 | if (m_pProfileToolButton)
|
---|
99 | {
|
---|
100 | m_pProfileToolButton->setIcon(UIIconPool::iconSet(":/cloud_profile_manager_16px.png",
|
---|
101 | ":/cloud_profile_manager_disabled_16px.png"));
|
---|
102 | pLayoutProfile->addWidget(m_pProfileToolButton);
|
---|
103 | }
|
---|
104 |
|
---|
105 | /* Add into layout: */
|
---|
106 | pLayoutLocation->addLayout(pLayoutProfile);
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | /* Add into tool-box: */
|
---|
111 | m_pToolBox->insertPage(0, pWidgetLocation, QString());
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* Prepare source widget: */
|
---|
115 | QWidget *pWidgetSource = new QWidget(m_pToolBox);
|
---|
116 | if (pWidgetSource)
|
---|
117 | {
|
---|
118 | /* Prepare source layout: */
|
---|
119 | QVBoxLayout *pLayoutSource = new QVBoxLayout(pWidgetSource);
|
---|
120 | if (pLayoutSource)
|
---|
121 | {
|
---|
122 | pLayoutSource->setContentsMargins(0, 0, 0, 0);
|
---|
123 |
|
---|
124 | /* Prepare source instances table: */
|
---|
125 | m_pSourceInstanceList = new QListWidget(pWidgetSource);
|
---|
126 | if (m_pSourceInstanceList)
|
---|
127 | {
|
---|
128 | /* A bit of look&feel: */
|
---|
129 | m_pSourceInstanceList->setAlternatingRowColors(true);
|
---|
130 | /* Allow to select more than one item to add: */
|
---|
131 | m_pSourceInstanceList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
---|
132 |
|
---|
133 | /* Add into layout: */
|
---|
134 | pLayoutSource->addWidget(m_pSourceInstanceList);
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | /* Add into tool-box: */
|
---|
139 | m_pToolBox->insertPage(1, pWidgetSource, QString());
|
---|
140 | }
|
---|
141 |
|
---|
142 | /* Add into layout: */
|
---|
143 | pLayoutMain->addWidget(m_pToolBox);
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | /* Setup connections: */
|
---|
148 | connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileRegistered,
|
---|
149 | this, &UIWizardAddCloudVMPageExpert::sltHandleProviderComboChange);
|
---|
150 | connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileChanged,
|
---|
151 | this, &UIWizardAddCloudVMPageExpert::sltHandleProviderComboChange);
|
---|
152 | connect(m_pProviderComboBox, &QIComboBox::activated,
|
---|
153 | this, &UIWizardAddCloudVMPageExpert::sltHandleProviderComboChange);
|
---|
154 | connect(m_pProfileComboBox, &QIComboBox::currentIndexChanged,
|
---|
155 | this, &UIWizardAddCloudVMPageExpert::sltHandleProfileComboChange);
|
---|
156 | connect(m_pProfileToolButton, &QIToolButton::clicked,
|
---|
157 | this, &UIWizardAddCloudVMPageExpert::sltHandleProfileButtonClick);
|
---|
158 | connect(m_pSourceInstanceList, &QListWidget::itemSelectionChanged,
|
---|
159 | this, &UIWizardAddCloudVMPageExpert::sltHandleSourceInstanceChange);
|
---|
160 | }
|
---|
161 |
|
---|
162 | UIWizardAddCloudVM *UIWizardAddCloudVMPageExpert::wizard() const
|
---|
163 | {
|
---|
164 | return qobject_cast<UIWizardAddCloudVM*>(UINativeWizardPage::wizard());
|
---|
165 | }
|
---|
166 |
|
---|
167 | void UIWizardAddCloudVMPageExpert::retranslateUi()
|
---|
168 | {
|
---|
169 | /* Translate tool-box: */
|
---|
170 | if (m_pToolBox)
|
---|
171 | {
|
---|
172 | m_pToolBox->setPageTitle(0, UIWizardAddCloudVM::tr("Location"));
|
---|
173 | m_pToolBox->setPageTitle(1, UIWizardAddCloudVM::tr("Source"));
|
---|
174 | }
|
---|
175 |
|
---|
176 | /* Translate profile stuff: */
|
---|
177 | if (m_pProfileToolButton)
|
---|
178 | m_pProfileToolButton->setToolTip(UIWizardAddCloudVM::tr("Open Cloud Profile Manager..."));
|
---|
179 |
|
---|
180 | /* Translate received values of Source combo-box.
|
---|
181 | * We are enumerating starting from 0 for simplicity: */
|
---|
182 | if (m_pProviderComboBox)
|
---|
183 | for (int i = 0; i < m_pProviderComboBox->count(); ++i)
|
---|
184 | {
|
---|
185 | m_pProviderComboBox->setItemText(i, m_pProviderComboBox->itemData(i, ProviderData_Name).toString());
|
---|
186 | m_pProviderComboBox->setItemData(i, UIWizardAddCloudVM::tr("Add VM from cloud service provider."), Qt::ToolTipRole);
|
---|
187 | }
|
---|
188 |
|
---|
189 | /* Update tool-tips: */
|
---|
190 | updateComboToolTip(m_pProviderComboBox);
|
---|
191 | }
|
---|
192 |
|
---|
193 | void UIWizardAddCloudVMPageExpert::initializePage()
|
---|
194 | {
|
---|
195 | /* Choose 1st tool to be chosen initially: */
|
---|
196 | m_pToolBox->setCurrentPage(0);
|
---|
197 | /* Populate providers: */
|
---|
198 | populateProviders(m_pProviderComboBox, wizard()->notificationCenter());
|
---|
199 | /* Translate providers: */
|
---|
200 | retranslateUi();
|
---|
201 | /* Fetch it, asynchronously: */
|
---|
202 | QMetaObject::invokeMethod(this, "sltHandleProviderComboChange", Qt::QueuedConnection);
|
---|
203 | /* Make image list focused by default: */
|
---|
204 | m_pSourceInstanceList->setFocus();
|
---|
205 | }
|
---|
206 |
|
---|
207 | bool UIWizardAddCloudVMPageExpert::isComplete() const
|
---|
208 | {
|
---|
209 | /* Initial result: */
|
---|
210 | bool fResult = true;
|
---|
211 |
|
---|
212 | /* Make sure client is not NULL and
|
---|
213 | * at least one instance is selected: */
|
---|
214 | fResult = wizard()->client().isNotNull()
|
---|
215 | && !wizard()->instanceIds().isEmpty();
|
---|
216 |
|
---|
217 | /* Return result: */
|
---|
218 | return fResult;
|
---|
219 | }
|
---|
220 |
|
---|
221 | bool UIWizardAddCloudVMPageExpert::validatePage()
|
---|
222 | {
|
---|
223 | /* Initial result: */
|
---|
224 | bool fResult = true;
|
---|
225 |
|
---|
226 | /* Try to add cloud VMs: */
|
---|
227 | fResult = wizard()->addCloudVMs();
|
---|
228 |
|
---|
229 | /* Return result: */
|
---|
230 | return fResult;
|
---|
231 | }
|
---|
232 |
|
---|
233 | void UIWizardAddCloudVMPageExpert::sltHandleProviderComboChange()
|
---|
234 | {
|
---|
235 | /* Update combo tool-tip: */
|
---|
236 | updateComboToolTip(m_pProviderComboBox);
|
---|
237 |
|
---|
238 | /* Update wizard fields: */
|
---|
239 | wizard()->setProviderShortName(m_pProviderComboBox->currentData(ProviderData_ShortName).toString());
|
---|
240 |
|
---|
241 | /* Update profiles: */
|
---|
242 | populateProfiles(m_pProfileComboBox, wizard()->notificationCenter(), wizard()->providerShortName(), wizard()->profileName());
|
---|
243 | sltHandleProfileComboChange();
|
---|
244 |
|
---|
245 | /* Notify about changes: */
|
---|
246 | emit completeChanged();
|
---|
247 | }
|
---|
248 |
|
---|
249 | void UIWizardAddCloudVMPageExpert::sltHandleProfileComboChange()
|
---|
250 | {
|
---|
251 | /* Update wizard fields: */
|
---|
252 | wizard()->setProfileName(m_pProfileComboBox->currentData(ProfileData_Name).toString());
|
---|
253 | wizard()->setClient(cloudClientByName(wizard()->providerShortName(), wizard()->profileName(), wizard()->notificationCenter()));
|
---|
254 |
|
---|
255 | /* Update profile instances: */
|
---|
256 | wizard()->wizardButton(WizardButtonType_Expert)->setEnabled(false);
|
---|
257 | populateProfileInstances(m_pSourceInstanceList, wizard()->notificationCenter(), wizard()->client());
|
---|
258 | wizard()->wizardButton(WizardButtonType_Expert)->setEnabled(true);
|
---|
259 | sltHandleSourceInstanceChange();
|
---|
260 |
|
---|
261 | /* Notify about changes: */
|
---|
262 | emit completeChanged();
|
---|
263 | }
|
---|
264 |
|
---|
265 | void UIWizardAddCloudVMPageExpert::sltHandleProfileButtonClick()
|
---|
266 | {
|
---|
267 | if (gpManager)
|
---|
268 | gpManager->openCloudProfileManager();
|
---|
269 | }
|
---|
270 |
|
---|
271 | void UIWizardAddCloudVMPageExpert::sltHandleSourceInstanceChange()
|
---|
272 | {
|
---|
273 | /* Update wizard fields: */
|
---|
274 | wizard()->setInstanceIds(currentListWidgetData(m_pSourceInstanceList));
|
---|
275 |
|
---|
276 | /* Notify about changes: */
|
---|
277 | emit completeChanged();
|
---|
278 | }
|
---|