Changeset 89999 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jul 2, 2021 11:34:16 AM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 145476
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp
r89985 r89999 1043 1043 UISafePointerWizardAddCloudVM pWizard = new UIWizardAddCloudVM(pWizardParent, m_pWidget->fullGroupName()); 1044 1044 windowManager().registerNewParent(pWizard, pWizardParent); 1045 pWizard->prepare();1046 1045 1047 1046 /* Execute wizard: */ -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/addcloudvm/UIWizardAddCloudVM.cpp
r86573 r89999 5 5 6 6 /* 7 * Copyright (C) 2009-202 0Oracle Corporation7 * Copyright (C) 2009-2021 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 24 24 25 25 /* COM includes: */ 26 #include "CCloudMachine.h" 26 27 #include "CProgress.h" 27 28 … … 30 31 const QString &strFullGroupName /* = QString() */, 31 32 WizardMode enmMode /* = WizardMode_Auto */) 32 : UI Wizard(pParent, WizardType_AddCloudVM, enmMode)33 : UINativeWizard(pParent, WizardType_AddCloudVM, enmMode) 33 34 , m_strFullGroupName(strFullGroupName) 34 35 { 35 36 #ifndef VBOX_WS_MAC 36 37 /* Assign watermark: */ 37 assignWatermark(":/wizard_new_cloud_vm.png");38 setPixmapName(":/wizard_new_cloud_vm.png"); 38 39 #else 39 40 /* Assign background image: */ 40 assignBackground(":/wizard_new_cloud_vm_bg.png");41 setPixmapName(":/wizard_new_cloud_vm_bg.png"); 41 42 #endif 42 }43 44 void UIWizardAddCloudVM::prepare()45 {46 /* Create corresponding pages: */47 switch (mode())48 {49 case WizardMode_Basic:50 {51 setPage(Page1, new UIWizardAddCloudVMPageBasic1);52 break;53 }54 case WizardMode_Expert:55 {56 setPage(PageExpert, new UIWizardAddCloudVMPageExpert);57 break;58 }59 default:60 {61 AssertMsgFailed(("Invalid mode: %d", mode()));62 break;63 }64 }65 /* Call to base-class: */66 UIWizard::prepare();67 43 } 68 44 … … 77 53 78 54 /* For each cloud instance name we have: */ 79 foreach (const QString &strInstanceName, field("instanceIds").toStringList())55 foreach (const QString &strInstanceName, instanceIds()) 80 56 { 81 57 /* Initiate cloud VM add procedure: */ … … 109 85 if (comMachine.isNotNull()) 110 86 { 111 uiCommon().notifyCloudMachineRegistered(field("source").toString(), 112 field("profileName").toString(), 87 /* Notify GUI about VM was added: */ 88 uiCommon().notifyCloudMachineRegistered(shortProviderName(), 89 profileName(), 113 90 comMachine); 91 92 /* Finally, success: */ 114 93 fResult = true; 115 94 } … … 123 102 } 124 103 104 void UIWizardAddCloudVM::populatePages() 105 { 106 /* Create corresponding pages: */ 107 switch (mode()) 108 { 109 case WizardMode_Basic: 110 { 111 addPage(new UIWizardAddCloudVMPageBasic1); 112 break; 113 } 114 case WizardMode_Expert: 115 { 116 addPage(new UIWizardAddCloudVMPageExpert); 117 break; 118 } 119 default: 120 { 121 AssertMsgFailed(("Invalid mode: %d", mode())); 122 break; 123 } 124 } 125 } 126 125 127 void UIWizardAddCloudVM::retranslateUi() 126 128 { 127 129 /* Call to base-class: */ 128 UI Wizard::retranslateUi();130 UINativeWizard::retranslateUi(); 129 131 130 132 /* Translate wizard: */ 131 133 setWindowTitle(tr("Add Cloud Virtual Machine")); 132 setButtonText(QWizard::FinishButton, tr("Add")); 134 /// @todo implement this? 135 //setButtonText(QWizard::FinishButton, tr("Add")); 133 136 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/addcloudvm/UIWizardAddCloudVM.h
r86345 r89999 5 5 6 6 /* 7 * Copyright (C) 2009-202 0Oracle Corporation7 * Copyright (C) 2009-2021 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 23 23 24 24 /* GUI includes: */ 25 #include "UI Wizard.h"25 #include "UINativeWizard.h" 26 26 27 27 /* COM includes: */ 28 28 #include "COMEnums.h" 29 29 #include "CCloudClient.h" 30 #include "CCloudMachine.h"31 30 32 31 /** Add Cloud VM wizard. */ 33 class UIWizardAddCloudVM : public UI Wizard32 class UIWizardAddCloudVM : public UINativeWizard 34 33 { 35 34 Q_OBJECT; 36 35 37 36 public: 38 39 /** Basic page IDs. */40 enum41 {42 Page143 };44 45 /** Expert page IDs. */46 enum47 {48 PageExpert49 };50 37 51 38 /** Constructs Add Cloud VM wizard passing @a pParent & @a enmMode to the base-class. … … 55 42 WizardMode enmMode = WizardMode_Auto); 56 43 57 /** Prepares all. */58 virtual void prepare() /* override */;59 60 44 /** Returns full group name. */ 61 45 QString fullGroupName() const { return m_strFullGroupName; } 46 47 /** Defines @a strShortProviderName. */ 48 void setShortProviderName(const QString &strShortProviderName) { m_strShortProviderName = strShortProviderName; } 49 /** Returns short provider name. */ 50 QString shortProviderName() const { return m_strShortProviderName; } 51 52 /** Defines @a strProfileName. */ 53 void setProfileName(const QString &strProfileName) { m_strProfileName = strProfileName; } 54 /** Returns profile name. */ 55 QString profileName() const { return m_strProfileName; } 56 57 /** Defines @a instanceIds. */ 58 void setInstanceIds(const QStringList &instanceIds) { m_instanceIds = instanceIds; } 59 /** Returns instance IDs. */ 60 QStringList instanceIds() const { return m_instanceIds; } 62 61 63 62 /** Defines Cloud @a comClient object wrapper. */ … … 71 70 protected: 72 71 72 /** Populates pages. */ 73 virtual void populatePages() /* override final */; 74 73 75 /** Handles translation event. */ 74 virtual void retranslateUi() /* override */;76 virtual void retranslateUi() /* override final */; 75 77 76 78 private: 77 79 78 80 /** Holds the full group name (/provider/profile) to add VM to. */ 79 QString m_strFullGroupName; 80 81 QString m_strFullGroupName; 82 /** Holds the short provider name. */ 83 QString m_strShortProviderName; 84 /** Holds the profile name. */ 85 QString m_strProfileName; 86 /** Holds the instance ids. */ 87 QStringList m_instanceIds; 81 88 /** Holds the Cloud Client object wrapper. */ 82 89 CCloudClient m_comClient; -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/addcloudvm/UIWizardAddCloudVMPageBasic1.cpp
r89998 r89999 5 5 6 6 /* 7 * Copyright (C) 2009-202 0Oracle Corporation7 * Copyright (C) 2009-2021 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 18 18 /* Qt includes: */ 19 #include <QGridLayout> 19 20 #include <QHeaderView> 20 #include <QGridLayout>21 21 #include <QLabel> 22 22 #include <QListWidget> 23 #include <QTableWidget>24 23 #include <QVBoxLayout> 25 24 … … 39 38 #include "CStringArray.h" 40 39 40 /* Namespaces: */ 41 using namespace UIWizardAddCloudVMPage1; 42 41 43 42 44 /********************************************************************************************************************************* 43 * Class UIWizardAddCloudVMPage1 implementation.*45 * Namespace UIWizardAddCloudVMPage1 implementation. * 44 46 *********************************************************************************************************************************/ 45 47 46 UIWizardAddCloudVMPage1::UIWizardAddCloudVMPage1() 47 : m_fPolished(false) 48 , m_pSourceLayout(0) 49 , m_pSourceLabel(0) 50 , m_pSourceComboBox(0) 51 , m_pCloudContainerLayout(0) 52 , m_pProfileLabel(0) 53 , m_pProfileComboBox(0) 54 , m_pProfileToolButton(0) 55 , m_pProfileInstanceLabel(0) 56 , m_pProfileInstanceList(0) 57 { 58 } 59 60 void UIWizardAddCloudVMPage1::populateSources() 61 { 62 /* To be executed just once, so combo should be empty: */ 63 AssertReturnVoid(m_pSourceComboBox->count() == 0); 64 65 /* Do we have OCI source? */ 66 bool fOCIPresent = false; 67 68 /* Main API request sequence, can be interrupted after any step: */ 69 do 70 { 71 /* Initialize Cloud Provider Manager: */ 72 CVirtualBox comVBox = uiCommon().virtualBox(); 73 m_comCloudProviderManager = comVBox.GetCloudProviderManager(); 74 if (!comVBox.isOk()) 75 { 76 msgCenter().cannotAcquireCloudProviderManager(comVBox); 77 break; 78 } 79 80 /* Acquire existing providers: */ 81 const QVector<CCloudProvider> providers = m_comCloudProviderManager.GetProviders(); 82 if (!m_comCloudProviderManager.isOk()) 83 { 84 msgCenter().cannotAcquireCloudProviderManagerParameter(m_comCloudProviderManager); 85 break; 86 } 87 88 /* Iterate through existing providers: */ 89 foreach (const CCloudProvider &comProvider, providers) 90 { 91 /* Skip if we have nothing to populate (file missing?): */ 92 if (comProvider.isNull()) 93 continue; 94 95 /* Compose empty item, fill it's data: */ 96 m_pSourceComboBox->addItem(QString()); 97 m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetId(), SourceData_ID); 98 m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetName(), SourceData_Name); 99 m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetShortName(), SourceData_ShortName); 100 if (m_pSourceComboBox->itemData(m_pSourceComboBox->count() - 1, SourceData_ShortName).toString() == "OCI") 101 fOCIPresent = true; 102 } 103 } 104 while (0); 105 106 /* Set default: */ 107 if (fOCIPresent) 108 setSource("OCI"); 109 } 110 111 void UIWizardAddCloudVMPage1::populateProfiles() 112 { 48 void UIWizardAddCloudVMPage1::populateProviders(QIComboBox *pCombo) 49 { 50 /* Sanity check: */ 51 AssertPtrReturnVoid(pCombo); 52 /* We need top-level parent as well: */ 53 QWidget *pParent = pCombo->window(); 54 AssertPtrReturnVoid(pParent); 55 113 56 /* Block signals while updating: */ 114 m_pProfileComboBox->blockSignals(true);57 pCombo->blockSignals(true); 115 58 116 59 /* Remember current item data to be able to restore it: */ 117 60 QString strOldData; 118 if (m_pProfileComboBox->currentIndex() != -1) 119 strOldData = m_pProfileComboBox->itemData(m_pProfileComboBox->currentIndex(), ProfileData_Name).toString(); 61 if (pCombo->currentIndex() != -1) 62 strOldData = pCombo->itemData(pCombo->currentIndex(), ProviderData_ShortName).toString(); 63 /* Otherwise "OCI" should be the default one: */ 120 64 else 65 strOldData = "OCI"; 66 67 /* Clear combo initially: */ 68 pCombo->clear(); 69 70 /* Iterate through existing providers: */ 71 foreach (const CCloudProvider &comProvider, listCloudProviders(pParent)) 72 { 73 /* Skip if we have nothing to populate (file missing?): */ 74 if (comProvider.isNull()) 75 continue; 76 /* Acquire provider name: */ 77 QString strProviderName; 78 if (!cloudProviderName(comProvider, strProviderName, pParent)) 79 continue; 80 /* Acquire provider short name: */ 81 QString strProviderShortName; 82 if (!cloudProviderShortName(comProvider, strProviderShortName, pParent)) 83 continue; 84 85 /* Compose empty item, fill the data: */ 86 pCombo->addItem(QString()); 87 pCombo->setItemData(pCombo->count() - 1, strProviderName, ProviderData_Name); 88 pCombo->setItemData(pCombo->count() - 1, strProviderShortName, ProviderData_ShortName); 89 } 90 91 /* Set previous/default item if possible: */ 92 int iNewIndex = -1; 93 if ( iNewIndex == -1 94 && !strOldData.isNull()) 95 iNewIndex = pCombo->findData(strOldData, ProviderData_ShortName); 96 if ( iNewIndex == -1 97 && pCombo->count() > 0) 98 iNewIndex = 0; 99 if (iNewIndex != -1) 100 pCombo->setCurrentIndex(iNewIndex); 101 102 /* Unblock signals after update: */ 103 pCombo->blockSignals(false); 104 } 105 106 void UIWizardAddCloudVMPage1::populateProfiles(QIComboBox *pCombo, const CCloudProvider &comProvider) 107 { 108 /* Sanity check: */ 109 AssertPtrReturnVoid(pCombo); 110 AssertReturnVoid(comProvider.isNotNull()); 111 /* We need top-level parent as well: */ 112 QWidget *pParent = pCombo->window(); 113 AssertPtrReturnVoid(pParent); 114 115 /* Block signals while updating: */ 116 pCombo->blockSignals(true); 117 118 /* Remember current item data to be able to restore it: */ 119 QString strOldData; 120 if (pCombo->currentIndex() != -1) 121 strOldData = pCombo->itemData(pCombo->currentIndex(), ProfileData_Name).toString(); 122 else 121 123 { 122 124 /* Try to fetch "old" profile name from wizard full group name: */ 123 UIWizardAddCloudVM *pWizard = qobject_cast<UIWizardAddCloudVM*>( wizardImp());125 UIWizardAddCloudVM *pWizard = qobject_cast<UIWizardAddCloudVM*>(pParent); 124 126 AssertPtrReturnVoid(pWizard); 125 127 const QString strFullGroupName = pWizard->fullGroupName(); … … 130 132 131 133 /* Clear combo initially: */ 132 m_pProfileComboBox->clear(); 133 /* Clear Cloud Provider: */ 134 m_comCloudProvider = CCloudProvider(); 135 136 /* If provider chosen: */ 137 if (!sourceId().isNull()) 138 { 139 /* Main API request sequence, can be interrupted after any step: */ 140 do 134 pCombo->clear(); 135 136 /* Iterate through existing profiles: */ 137 foreach (const CCloudProfile &comProfile, listCloudProfiles(comProvider, pParent)) 138 { 139 /* Skip if we have nothing to populate (wtf happened?): */ 140 if (comProfile.isNull()) 141 continue; 142 /* Acquire profile name: */ 143 QString strProfileName; 144 if (!cloudProfileName(comProfile, strProfileName, pParent)) 145 continue; 146 147 /* Compose item, fill the data: */ 148 pCombo->addItem(strProfileName); 149 pCombo->setItemData(pCombo->count() - 1, strProfileName, ProfileData_Name); 150 } 151 152 /* Set previous/default item if possible: */ 153 int iNewIndex = -1; 154 if ( iNewIndex == -1 155 && !strOldData.isNull()) 156 iNewIndex = pCombo->findData(strOldData, ProfileData_Name); 157 if ( iNewIndex == -1 158 && pCombo->count() > 0) 159 iNewIndex = 0; 160 if (iNewIndex != -1) 161 pCombo->setCurrentIndex(iNewIndex); 162 163 /* Unblock signals after update: */ 164 pCombo->blockSignals(false); 165 } 166 167 void UIWizardAddCloudVMPage1::populateProfileInstances(QListWidget *pList, const CCloudClient &comClient) 168 { 169 /* Sanity check: */ 170 AssertPtrReturnVoid(pList); 171 AssertReturnVoid(comClient.isNotNull()); 172 /* We need top-level parent as well: */ 173 QWidget *pParent = pList->window(); 174 AssertPtrReturnVoid(pParent); 175 176 /* Block signals while updating: */ 177 pList->blockSignals(true); 178 179 /* Clear list initially: */ 180 pList->clear(); 181 182 /* Gather instance names and ids: */ 183 CStringArray comNames; 184 CStringArray comIDs; 185 if (listCloudSourceInstances(comClient, comNames, comIDs, pParent)) 186 { 187 /* Push acquired names to list rows: */ 188 const QVector<QString> names = comNames.GetValues(); 189 const QVector<QString> ids = comIDs.GetValues(); 190 for (int i = 0; i < names.size(); ++i) 141 191 { 142 /* (Re)initialize Cloud Provider: */143 m_comCloudProvider = m_comCloudProviderManager.GetProviderById(sourceId());144 if ( !m_comCloudProviderManager.isOk())192 /* Create list item: */ 193 QListWidgetItem *pItem = new QListWidgetItem(names.at(i), pList); 194 if (pItem) 145 195 { 146 msgCenter().cannotFindCloudProvider(m_comCloudProviderManager, sourceId());147 break;196 pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable); 197 pItem->setData(Qt::UserRole, ids.at(i)); 148 198 } 149 150 /* Acquire existing profile names: */151 const QVector<QString> profileNames = m_comCloudProvider.GetProfileNames();152 if (!m_comCloudProvider.isOk())153 {154 msgCenter().cannotAcquireCloudProviderParameter(m_comCloudProvider);155 break;156 }157 158 /* Iterate through existing profile names: */159 foreach (const QString &strProfileName, profileNames)160 {161 /* Skip if we have nothing to show (wtf happened?): */162 if (strProfileName.isEmpty())163 continue;164 165 /* Compose item, fill it's data: */166 m_pProfileComboBox->addItem(strProfileName);167 m_pProfileComboBox->setItemData(m_pProfileComboBox->count() - 1, strProfileName, ProfileData_Name);168 }169 170 /* Set previous/default item if possible: */171 int iNewIndex = -1;172 if ( iNewIndex == -1173 && !strOldData.isNull())174 iNewIndex = m_pProfileComboBox->findData(strOldData, ProfileData_Name);175 if ( iNewIndex == -1176 && m_pProfileComboBox->count() > 0)177 iNewIndex = 0;178 if (iNewIndex != -1)179 m_pProfileComboBox->setCurrentIndex(iNewIndex);180 199 } 181 while (0); 182 } 200 } 201 202 /* Choose the 1st one by default if possible: */ 203 if (pList->count()) 204 pList->setCurrentRow(0); 183 205 184 206 /* Unblock signals after update: */ 185 m_pProfileComboBox->blockSignals(false); 186 } 187 188 void UIWizardAddCloudVMPage1::populateProfile() 189 { 190 /* Clear Cloud Profile: */ 191 m_comCloudProfile = CCloudProfile(); 192 193 /* If both provider and profile chosen: */ 194 if (m_comCloudProvider.isNotNull() && !profileName().isNull()) 195 { 196 /* Acquire Cloud Profile: */ 197 m_comCloudProfile = m_comCloudProvider.GetProfileByName(profileName()); 198 /* Show error message if necessary: */ 199 if (!m_comCloudProvider.isOk()) 200 msgCenter().cannotFindCloudProfile(m_comCloudProvider, profileName()); 201 } 202 } 203 204 void UIWizardAddCloudVMPage1::populateProfileInstances() 205 { 206 /* Block signals while updating: */ 207 m_pProfileInstanceList->blockSignals(true); 208 209 /* Clear list initially: */ 210 m_pProfileInstanceList->clear(); 211 /* Clear Cloud Client: */ 212 setClient(CCloudClient()); 213 214 /* If profile chosen: */ 215 if (m_comCloudProfile.isNotNull()) 216 { 217 /* Main API request sequence, can be interrupted after any step: */ 218 do 219 { 220 /* Acquire Cloud Client: */ 221 CCloudClient comCloudClient = m_comCloudProfile.CreateCloudClient(); 222 if (!m_comCloudProfile.isOk()) 223 { 224 msgCenter().cannotCreateCloudClient(m_comCloudProfile); 225 break; 226 } 227 228 /* Remember Cloud Client: */ 229 setClient(comCloudClient); 230 231 /* Gather instance names and ids: */ 232 CStringArray comNames; 233 CStringArray comIDs; 234 if (listCloudSourceInstances(comCloudClient, comNames, comIDs, wizardImp())) 235 { 236 /* Push acquired names to list rows: */ 237 const QVector<QString> names = comNames.GetValues(); 238 const QVector<QString> ids = comIDs.GetValues(); 239 for (int i = 0; i < names.size(); ++i) 240 { 241 /* Create list item: */ 242 QListWidgetItem *pItem = new QListWidgetItem(names.at(i), m_pProfileInstanceList); 243 if (pItem) 244 { 245 pItem->setFlags(pItem->flags() & ~Qt::ItemIsEditable); 246 pItem->setData(Qt::UserRole, ids.at(i)); 247 } 248 } 249 } 250 251 /* Choose the 1st one by default if possible: */ 252 if (m_pProfileInstanceList->count()) 253 m_pProfileInstanceList->setCurrentRow(0); 254 } 255 while (0); 256 } 257 258 /* Unblock signals after update: */ 259 m_pProfileInstanceList->blockSignals(false); 260 } 261 262 void UIWizardAddCloudVMPage1::updateSourceComboToolTip() 263 { 264 const int iCurrentIndex = m_pSourceComboBox->currentIndex(); 207 pList->blockSignals(false); 208 } 209 210 void UIWizardAddCloudVMPage1::updateComboToolTip(QIComboBox *pCombo) 211 { 212 /* Sanity check: */ 213 AssertPtrReturnVoid(pCombo); 214 215 const int iCurrentIndex = pCombo->currentIndex(); 265 216 if (iCurrentIndex != -1) 266 217 { 267 const QString strCurrentToolTip = m_pSourceComboBox->itemData(iCurrentIndex, Qt::ToolTipRole).toString(); 268 AssertMsg(!strCurrentToolTip.isEmpty(), ("Data not found!")); 269 m_pSourceComboBox->setToolTip(strCurrentToolTip); 270 } 271 } 272 273 void UIWizardAddCloudVMPage1::setSource(const QString &strSource) 274 { 275 const int iIndex = m_pSourceComboBox->findData(strSource, SourceData_ShortName); 276 AssertMsg(iIndex != -1, ("Data not found!")); 277 m_pSourceComboBox->setCurrentIndex(iIndex); 278 } 279 280 QString UIWizardAddCloudVMPage1::source() const 281 { 282 const int iIndex = m_pSourceComboBox->currentIndex(); 283 return m_pSourceComboBox->itemData(iIndex, SourceData_ShortName).toString(); 284 } 285 286 QUuid UIWizardAddCloudVMPage1::sourceId() const 287 { 288 const int iIndex = m_pSourceComboBox->currentIndex(); 289 return m_pSourceComboBox->itemData(iIndex, SourceData_ID).toUuid(); 290 } 291 292 QString UIWizardAddCloudVMPage1::profileName() const 293 { 294 const int iIndex = m_pProfileComboBox->currentIndex(); 295 return m_pProfileComboBox->itemData(iIndex, ProfileData_Name).toString(); 296 } 297 298 QStringList UIWizardAddCloudVMPage1::instanceIds() const 218 const QString strCurrentToolTip = pCombo->itemData(iCurrentIndex, Qt::ToolTipRole).toString(); 219 AssertMsg(!strCurrentToolTip.isEmpty(), ("Tool-tip data not found!\n")); 220 pCombo->setToolTip(strCurrentToolTip); 221 } 222 } 223 224 QStringList UIWizardAddCloudVMPage1::currentListWidgetData(QListWidget *pList) 299 225 { 300 226 QStringList result; 301 foreach (QListWidgetItem *pItem, m_pProfileInstanceList->selectedItems())227 foreach (QListWidgetItem *pItem, pList->selectedItems()) 302 228 result << pItem->data(Qt::UserRole).toString(); 303 229 return result; 304 }305 306 void UIWizardAddCloudVMPage1::setClient(const CCloudClient &comClient)307 {308 qobject_cast<UIWizardAddCloudVM*>(wizardImp())->setClient(comClient);309 }310 311 CCloudClient UIWizardAddCloudVMPage1::client() const312 {313 return qobject_cast<UIWizardAddCloudVM*>(wizardImp())->client();314 230 } 315 231 … … 321 237 UIWizardAddCloudVMPageBasic1::UIWizardAddCloudVMPageBasic1() 322 238 : m_pLabelMain(0) 239 , m_pProviderLayout(0) 240 , m_pProviderLabel(0) 241 , m_pProviderComboBox(0) 323 242 , m_pLabelDescription(0) 324 { 325 /* Create main layout: */ 326 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 327 if (pMainLayout) 328 { 329 /* Create main label: */ 243 , m_pOptionsLayout(0) 244 , m_pProfileLabel(0) 245 , m_pProfileComboBox(0) 246 , m_pProfileToolButton(0) 247 , m_pSourceInstanceLabel(0) 248 , m_pSourceInstanceList(0) 249 { 250 /* Prepare main layout: */ 251 QVBoxLayout *pLayoutMain = new QVBoxLayout(this); 252 if (pLayoutMain) 253 { 254 /* Prepare main label: */ 330 255 m_pLabelMain = new QIRichTextLabel(this); 331 256 if (m_pLabelMain) 257 pLayoutMain->addWidget(m_pLabelMain); 258 259 /* Prepare provider layout: */ 260 m_pProviderLayout = new QGridLayout; 261 if (m_pProviderLayout) 332 262 { 263 m_pProviderLayout->setContentsMargins(0, 0, 0, 0); 264 m_pProviderLayout->setColumnStretch(0, 0); 265 m_pProviderLayout->setColumnStretch(1, 1); 266 267 /* Prepare provider label: */ 268 m_pProviderLabel = new QLabel(this); 269 if (m_pProviderLabel) 270 m_pProviderLayout->addWidget(m_pProviderLabel, 0, 0, Qt::AlignRight); 271 /* Prepare provider combo-box: */ 272 m_pProviderComboBox = new QIComboBox(this); 273 if (m_pProviderComboBox) 274 { 275 m_pProviderLabel->setBuddy(m_pProviderComboBox); 276 m_pProviderLayout->addWidget(m_pProviderComboBox, 0, 1); 277 } 278 333 279 /* Add into layout: */ 334 p MainLayout->addWidget(m_pLabelMain);280 pLayoutMain->addLayout(m_pProviderLayout); 335 281 } 336 282 337 /* Create source layout: */ 338 m_pSourceLayout = new QGridLayout; 339 if (m_pSourceLayout) 340 { 341 m_pSourceLayout->setContentsMargins(0, 0, 0, 0); 342 m_pSourceLayout->setColumnStretch(0, 0); 343 m_pSourceLayout->setColumnStretch(1, 1); 344 345 /* Create source label: */ 346 m_pSourceLabel = new QLabel(this); 347 if (m_pSourceLabel) 348 { 349 /* Add into layout: */ 350 m_pSourceLayout->addWidget(m_pSourceLabel, 0, 0, Qt::AlignRight); 351 } 352 /* Create source selector: */ 353 m_pSourceComboBox = new QIComboBox(this); 354 if (m_pSourceComboBox) 355 { 356 m_pSourceLabel->setBuddy(m_pSourceComboBox); 357 358 /* Add into layout: */ 359 m_pSourceLayout->addWidget(m_pSourceComboBox, 0, 1); 360 } 361 362 /* Add into layout: */ 363 pMainLayout->addLayout(m_pSourceLayout); 364 } 365 366 /* Create description label: */ 283 /* Prepare description label: */ 367 284 m_pLabelDescription = new QIRichTextLabel(this); 368 285 if (m_pLabelDescription) 286 pLayoutMain->addWidget(m_pLabelDescription); 287 288 /* Prepare options layout: */ 289 m_pOptionsLayout = new QGridLayout; 290 if (m_pOptionsLayout) 369 291 { 370 /* Add into layout: */ 371 pMainLayout->addWidget(m_pLabelDescription); 372 } 373 374 /* Create cloud container layout: */ 375 m_pCloudContainerLayout = new QGridLayout; 376 if (m_pCloudContainerLayout) 377 { 378 m_pCloudContainerLayout->setContentsMargins(0, 0, 0, 0); 379 m_pCloudContainerLayout->setColumnStretch(0, 0); 380 m_pCloudContainerLayout->setColumnStretch(1, 1); 381 m_pCloudContainerLayout->setRowStretch(1, 0); 382 m_pCloudContainerLayout->setRowStretch(2, 1); 383 384 /* Create profile label: */ 292 m_pOptionsLayout->setContentsMargins(0, 0, 0, 0); 293 m_pOptionsLayout->setColumnStretch(0, 0); 294 m_pOptionsLayout->setColumnStretch(1, 1); 295 m_pOptionsLayout->setRowStretch(1, 0); 296 m_pOptionsLayout->setRowStretch(2, 1); 297 298 /* Prepare profile label: */ 385 299 m_pProfileLabel = new QLabel(this); 386 300 if (m_pProfileLabel) 301 m_pOptionsLayout->addWidget(m_pProfileLabel, 0, 0, Qt::AlignRight); 302 303 /* Prepare profile layout: */ 304 QHBoxLayout *pProfileLayout = new QHBoxLayout; 305 if (pProfileLayout) 387 306 { 388 /* Add into layout: */ 389 m_pCloudContainerLayout->addWidget(m_pProfileLabel, 0, 0, Qt::AlignRight); 390 } 391 /* Create sub-layout: */ 392 QHBoxLayout *pSubLayout = new QHBoxLayout; 393 if (pSubLayout) 394 { 395 pSubLayout->setContentsMargins(0, 0, 0, 0); 396 pSubLayout->setSpacing(1); 397 398 /* Create profile combo-box: */ 307 pProfileLayout->setContentsMargins(0, 0, 0, 0); 308 pProfileLayout->setSpacing(1); 309 310 /* Prepare profile combo-box: */ 399 311 m_pProfileComboBox = new QIComboBox(this); 400 312 if (m_pProfileComboBox) 401 313 { 402 314 m_pProfileLabel->setBuddy(m_pProfileComboBox); 403 404 /* Add into layout: */ 405 pSubLayout->addWidget(m_pProfileComboBox); 315 pProfileLayout->addWidget(m_pProfileComboBox); 406 316 } 407 /* Create profile tool-button: */ 317 318 /* Prepare profile tool-button: */ 408 319 m_pProfileToolButton = new QIToolButton(this); 409 320 if (m_pProfileToolButton) … … 411 322 m_pProfileToolButton->setIcon(UIIconPool::iconSet(":/cloud_profile_manager_16px.png", 412 323 ":/cloud_profile_manager_disabled_16px.png")); 413 414 /* Add into layout: */ 415 pSubLayout->addWidget(m_pProfileToolButton); 324 pProfileLayout->addWidget(m_pProfileToolButton); 416 325 } 417 326 418 327 /* Add into layout: */ 419 m_p CloudContainerLayout->addLayout(pSubLayout, 0, 1);328 m_pOptionsLayout->addLayout(pProfileLayout, 0, 1); 420 329 } 421 330 422 /* Create profile instance label: */ 423 m_pProfileInstanceLabel = new QLabel(this); 424 if (m_pProfileInstanceLabel) 331 /* Prepare source instance label: */ 332 m_pSourceInstanceLabel = new QLabel(this); 333 if (m_pSourceInstanceLabel) 334 m_pOptionsLayout->addWidget(m_pSourceInstanceLabel, 1, 0, Qt::AlignRight); 335 336 /* Prepare source instances table: */ 337 m_pSourceInstanceList = new QListWidget(this); 338 if (m_pSourceInstanceList) 425 339 { 426 /* Add into layout: */ 427 m_pCloudContainerLayout->addWidget(m_pProfileInstanceLabel, 1, 0, Qt::AlignRight); 428 } 429 /* Create profile instances table: */ 430 m_pProfileInstanceList = new QListWidget(this); 431 if (m_pProfileInstanceList) 432 { 433 m_pProfileInstanceLabel->setBuddy(m_pProfileInstanceLabel); 434 const QFontMetrics fm(m_pProfileInstanceList->font()); 340 m_pSourceInstanceLabel->setBuddy(m_pSourceInstanceLabel); 341 /* Make source image list fit 50 symbols 342 * horizontally and 8 lines vertically: */ 343 const QFontMetrics fm(m_pSourceInstanceList->font()); 435 344 const int iFontWidth = fm.width('x'); 436 345 const int iTotalWidth = 50 * iFontWidth; 437 346 const int iFontHeight = fm.height(); 438 const int iTotalHeight = 4 * iFontHeight; 439 m_pProfileInstanceList->setMinimumSize(QSize(iTotalWidth, iTotalHeight)); 440 //m_pProfileInstanceList->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 441 m_pProfileInstanceList->setAlternatingRowColors(true); 442 m_pProfileInstanceList->setSelectionMode(QAbstractItemView::ExtendedSelection); 347 const int iTotalHeight = 8 * iFontHeight; 348 m_pSourceInstanceList->setMinimumSize(QSize(iTotalWidth, iTotalHeight)); 349 m_pSourceInstanceList->setAlternatingRowColors(true); 350 m_pSourceInstanceList->setSelectionMode(QAbstractItemView::ExtendedSelection); 443 351 444 352 /* Add into layout: */ 445 m_p CloudContainerLayout->addWidget(m_pProfileInstanceList, 1, 1, 2, 1);353 m_pOptionsLayout->addWidget(m_pSourceInstanceList, 1, 1, 2, 1); 446 354 } 447 355 448 356 /* Add into layout: */ 449 p MainLayout->addLayout(m_pCloudContainerLayout);357 pLayoutMain->addLayout(m_pOptionsLayout); 450 358 } 451 359 } … … 453 361 /* Setup connections: */ 454 362 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileRegistered, 455 this, &UIWizardAddCloudVMPageBasic1::sltHandle SourceChange);363 this, &UIWizardAddCloudVMPageBasic1::sltHandleProviderComboChange); 456 364 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileChanged, 457 this, &UIWizardAddCloudVMPageBasic1::sltHandle SourceChange);458 connect(m_p SourceComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::activated),459 this, &UIWizardAddCloudVMPageBasic1::sltHandle SourceChange);365 this, &UIWizardAddCloudVMPageBasic1::sltHandleProviderComboChange); 366 connect(m_pProviderComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::activated), 367 this, &UIWizardAddCloudVMPageBasic1::sltHandleProviderComboChange); 460 368 connect(m_pProfileComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::currentIndexChanged), 461 369 this, &UIWizardAddCloudVMPageBasic1::sltHandleProfileComboChange); 462 370 connect(m_pProfileToolButton, &QIToolButton::clicked, 463 371 this, &UIWizardAddCloudVMPageBasic1::sltHandleProfileButtonClick); 464 connect(m_pProfileInstanceList, &QListWidget::currentRowChanged, 465 this, &UIWizardAddCloudVMPageBasic1::completeChanged); 466 467 /* Register fields: */ 468 registerField("source", this, "source"); 469 registerField("profileName", this, "profileName"); 470 registerField("instanceIds", this, "instanceIds"); 372 connect(m_pSourceInstanceList, &QListWidget::currentRowChanged, 373 this, &UIWizardAddCloudVMPageBasic1::sltHandleSourceInstanceChange); 471 374 } 472 375 … … 480 383 "be one of known cloud service providers below.")); 481 384 482 /* Translate sourcelabel: */483 m_p SourceLabel->setText(UIWizardAddCloudVM::tr("&Source:"));385 /* Translate provider label: */ 386 m_pProviderLabel->setText(UIWizardAddCloudVM::tr("&Source:")); 484 387 /* Translate received values of Source combo-box. 485 388 * We are enumerating starting from 0 for simplicity: */ 486 for (int i = 0; i < m_p SourceComboBox->count(); ++i)487 { 488 m_p SourceComboBox->setItemText(i, m_pSourceComboBox->itemData(i, SourceData_Name).toString());489 m_p SourceComboBox->setItemData(i, UIWizardAddCloudVM::tr("Add VM from cloud service provider."), Qt::ToolTipRole);389 for (int i = 0; i < m_pProviderComboBox->count(); ++i) 390 { 391 m_pProviderComboBox->setItemText(i, m_pProviderComboBox->itemData(i, ProviderData_Name).toString()); 392 m_pProviderComboBox->setItemData(i, UIWizardAddCloudVM::tr("Add VM from cloud service provider."), Qt::ToolTipRole); 490 393 } 491 394 … … 499 402 m_pProfileLabel->setText(UIWizardAddCloudVM::tr("&Profile:")); 500 403 m_pProfileToolButton->setToolTip(UIWizardAddCloudVM::tr("Open Cloud Profile Manager...")); 501 m_p ProfileInstanceLabel->setText(UIWizardAddCloudVM::tr("&Instances:"));404 m_pSourceInstanceLabel->setText(UIWizardAddCloudVM::tr("&Instances:")); 502 405 503 406 /* Adjust label widths: */ 504 407 QList<QWidget*> labels; 505 labels << m_p SourceLabel;408 labels << m_pProviderLabel; 506 409 labels << m_pProfileLabel; 507 labels << m_p ProfileInstanceLabel;410 labels << m_pSourceInstanceLabel; 508 411 int iMaxWidth = 0; 509 412 foreach (QWidget *pLabel, labels) 510 413 iMaxWidth = qMax(iMaxWidth, pLabel->minimumSizeHint().width()); 511 m_p SourceLayout->setColumnMinimumWidth(0, iMaxWidth);512 m_p CloudContainerLayout->setColumnMinimumWidth(0, iMaxWidth);414 m_pProviderLayout->setColumnMinimumWidth(0, iMaxWidth); 415 m_pOptionsLayout->setColumnMinimumWidth(0, iMaxWidth); 513 416 514 417 /* Update tool-tips: */ 515 update SourceComboToolTip();418 updateComboToolTip(m_pProviderComboBox); 516 419 } 517 420 518 421 void UIWizardAddCloudVMPageBasic1::initializePage() 519 422 { 520 /* If wasn't polished yet: */ 521 if (!m_fPolished) 522 { 523 /* Populate sources: */ 524 populateSources(); 525 /* Choose one of them, asynchronously: */ 526 QMetaObject::invokeMethod(this, "sltHandleSourceChange", Qt::QueuedConnection); 527 m_fPolished = true; 528 } 529 530 /* Translate page: */ 423 /* Populate providers: */ 424 populateProviders(m_pProviderComboBox); 425 /* Translate providers: */ 531 426 retranslateUi(); 427 /* Fetch it, asynchronously: */ 428 QMetaObject::invokeMethod(this, "sltHandleProviderComboChange", Qt::QueuedConnection); 429 /* Make image list focused by default: */ 430 m_pSourceInstanceList->setFocus(); 532 431 } 533 432 … … 551 450 bool fResult = true; 552 451 553 /* Lock finish button: */554 startProcessing();555 556 452 /* Try to add cloud VMs: */ 557 453 fResult = qobject_cast<UIWizardAddCloudVM*>(wizard())->addCloudVMs(); 558 454 559 /* Unlock finish button: */560 endProcessing();561 562 455 /* Return result: */ 563 456 return fResult; 564 457 } 565 458 566 void UIWizardAddCloudVMPageBasic1::sltHandleSourceChange() 567 { 568 /* Update tool-tip: */ 569 updateSourceComboToolTip(); 570 571 /* Make instance list focused by default: */ 572 m_pProfileInstanceList->setFocus(); 573 574 /* Refresh required settings: */ 575 populateProfiles(); 576 populateProfile(); 577 populateProfileInstances(); 459 void UIWizardAddCloudVMPageBasic1::sltHandleProviderComboChange() 460 { 461 updateProvider(); 578 462 emit completeChanged(); 579 463 } … … 581 465 void UIWizardAddCloudVMPageBasic1::sltHandleProfileComboChange() 582 466 { 583 /* Refresh required settings: */ 584 populateProfile(); 585 populateProfileInstances(); 467 updateProfile(); 586 468 emit completeChanged(); 587 469 } … … 589 471 void UIWizardAddCloudVMPageBasic1::sltHandleProfileButtonClick() 590 472 { 591 /* Open Cloud Profile Manager: */592 473 if (gpManager) 593 474 gpManager->openCloudProfileManager(); 594 475 } 476 477 void UIWizardAddCloudVMPageBasic1::sltHandleSourceInstanceChange() 478 { 479 updateSourceInstance(); 480 emit completeChanged(); 481 } 482 483 void UIWizardAddCloudVMPageBasic1::setShortProviderName(const QString &strShortProviderName) 484 { 485 qobject_cast<UIWizardAddCloudVM*>(wizard())->setShortProviderName(strShortProviderName); 486 } 487 488 QString UIWizardAddCloudVMPageBasic1::shortProviderName() const 489 { 490 return qobject_cast<UIWizardAddCloudVM*>(wizard())->shortProviderName(); 491 } 492 493 void UIWizardAddCloudVMPageBasic1::setProfileName(const QString &strProfileName) 494 { 495 qobject_cast<UIWizardAddCloudVM*>(wizard())->setProfileName(strProfileName); 496 } 497 498 QString UIWizardAddCloudVMPageBasic1::profileName() const 499 { 500 return qobject_cast<UIWizardAddCloudVM*>(wizard())->profileName(); 501 } 502 503 void UIWizardAddCloudVMPageBasic1::setClient(const CCloudClient &comClient) 504 { 505 qobject_cast<UIWizardAddCloudVM*>(wizard())->setClient(comClient); 506 } 507 508 CCloudClient UIWizardAddCloudVMPageBasic1::client() const 509 { 510 return qobject_cast<UIWizardAddCloudVM*>(wizard())->client(); 511 } 512 513 void UIWizardAddCloudVMPageBasic1::setInstanceIds(const QStringList &instanceIds) 514 { 515 qobject_cast<UIWizardAddCloudVM*>(wizard())->setInstanceIds(instanceIds); 516 } 517 518 QStringList UIWizardAddCloudVMPageBasic1::instanceIds() const 519 { 520 return qobject_cast<UIWizardAddCloudVM*>(wizard())->instanceIds(); 521 } 522 523 void UIWizardAddCloudVMPageBasic1::updateProvider() 524 { 525 updateComboToolTip(m_pProviderComboBox); 526 setShortProviderName(m_pProviderComboBox->currentData(ProviderData_ShortName).toString()); 527 CCloudProvider comCloudProvider = cloudProviderByShortName(shortProviderName(), wizard()); 528 populateProfiles(m_pProfileComboBox, comCloudProvider); 529 updateProfile(); 530 } 531 532 void UIWizardAddCloudVMPageBasic1::updateProfile() 533 { 534 setProfileName(m_pProfileComboBox->currentData(ProfileData_Name).toString()); 535 setClient(cloudClientByName(shortProviderName(), profileName(), wizard())); 536 populateProfileInstances(m_pSourceInstanceList, client()); 537 updateSourceInstance(); 538 } 539 540 void UIWizardAddCloudVMPageBasic1::updateSourceInstance() 541 { 542 setInstanceIds(currentListWidgetData(m_pSourceInstanceList)); 543 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/addcloudvm/UIWizardAddCloudVMPageBasic1.h
r86346 r89999 5 5 6 6 /* 7 * Copyright (C) 2009-202 0Oracle Corporation7 * Copyright (C) 2009-2021 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 23 23 24 24 /* GUI includes: */ 25 #include "UI WizardPage.h"25 #include "UINativeWizardPage.h" 26 26 27 27 /* COM includes: */ 28 28 #include "COMEnums.h" 29 29 #include "CCloudClient.h" 30 #include "CCloudProfile.h"31 #include "CCloudProvider.h"32 #include "CCloudProviderManager.h"33 30 34 31 /* Forward declarations: */ … … 36 33 class QLabel; 37 34 class QListWidget; 38 class QTableWidget;39 35 class QIComboBox; 40 36 class QIRichTextLabel; 41 37 class QIToolButton; 42 38 43 /** Sourcecombo data fields. */39 /** Provider combo data fields. */ 44 40 enum 45 41 { 46 SourceData_ID = Qt::UserRole + 1, 47 SourceData_Name = Qt::UserRole + 2, 48 SourceData_ShortName = Qt::UserRole + 3 42 ProviderData_Name = Qt::UserRole + 1, 43 ProviderData_ShortName = Qt::UserRole + 2 49 44 }; 50 45 … … 55 50 }; 56 51 57 /** UIWizardPageBase extensionfor 1st page of the Add Cloud VM wizard. */58 class UIWizardAddCloudVMPage1 : public UIWizardPageBase 52 /** Namespace for 1st page of the Add Cloud VM wizard. */ 53 namespace UIWizardAddCloudVMPage1 59 54 { 60 protected: 55 /** Populates @a pCombo with known providers. */ 56 void populateProviders(QIComboBox *pCombo); 57 /** Populates @a pCombo with known profiles of @a comProvider specified. */ 58 void populateProfiles(QIComboBox *pCombo, const CCloudProvider &comProvider); 59 /** Populates @a pList with profile instances available in @a comClient. */ 60 void populateProfileInstances(QListWidget *pList, const CCloudClient &comClient); 61 61 62 /** Constructs 1st page base. */63 UIWizardAddCloudVMPage1();62 /** Updates @a pCombo tool-tips. */ 63 void updateComboToolTip(QIComboBox *pCombo); 64 64 65 /** Populates sources. */ 66 void populateSources(); 67 /** Populates profiles. */ 68 void populateProfiles(); 69 /** Populates profile. */ 70 void populateProfile(); 71 /** Populates profile instances. */ 72 void populateProfileInstances(); 65 /** Returns current user data for @a pList specified. */ 66 QStringList currentListWidgetData(QListWidget *pList); 67 } 73 68 74 /** Updates source combo tool-tips. */ 75 void updateSourceComboToolTip(); 76 77 /** Defines @a strSource. */ 78 void setSource(const QString &strSource); 79 /** Returns source. */ 80 QString source() const; 81 /** Returns source ID. */ 82 QUuid sourceId() const; 83 84 /** Returns profile name. */ 85 QString profileName() const; 86 /** Returns instance IDs. */ 87 QStringList instanceIds() const; 88 89 /** Defines Cloud @a comClient object. */ 90 void setClient(const CCloudClient &comClient); 91 /** Returns Cloud Client object. */ 92 CCloudClient client() const; 93 94 /** Holds whether starting page was polished. */ 95 bool m_fPolished; 96 97 /** Holds the Cloud Provider Manager reference. */ 98 CCloudProviderManager m_comCloudProviderManager; 99 /** Holds the Cloud Provider object reference. */ 100 CCloudProvider m_comCloudProvider; 101 /** Holds the Cloud Profile object reference. */ 102 CCloudProfile m_comCloudProfile; 103 104 /** Holds the source layout instance. */ 105 QGridLayout *m_pSourceLayout; 106 /** Holds the source type label instance. */ 107 QLabel *m_pSourceLabel; 108 /** Holds the source type combo-box instance. */ 109 QIComboBox *m_pSourceComboBox; 110 111 /** Holds the cloud container layout instance. */ 112 QGridLayout *m_pCloudContainerLayout; 113 /** Holds the profile label instance. */ 114 QLabel *m_pProfileLabel; 115 /** Holds the profile combo-box instance. */ 116 QIComboBox *m_pProfileComboBox; 117 /** Holds the profile management tool-button instance. */ 118 QIToolButton *m_pProfileToolButton; 119 /** Holds the profile instance label instance. */ 120 QLabel *m_pProfileInstanceLabel; 121 /** Holds the profile instance list instance. */ 122 QListWidget *m_pProfileInstanceList; 123 }; 124 125 /** UIWizardPage extension for 1st page of the Add Cloud VM wizard, extends UIWizardAddCloudVMPage1 as well. */ 126 class UIWizardAddCloudVMPageBasic1 : public UIWizardPage, public UIWizardAddCloudVMPage1 69 /** UINativeWizardPage extension for 1st page of the Add Cloud VM wizard, 70 * based on UIWizardAddCloudVMPage1 namespace functions. */ 71 class UIWizardAddCloudVMPageBasic1 : public UINativeWizardPage 127 72 { 128 73 Q_OBJECT; 129 Q_PROPERTY(QString source READ source);130 Q_PROPERTY(QString profileName READ profileName);131 Q_PROPERTY(QStringList instanceIds READ instanceIds);132 74 133 75 public: … … 138 80 protected: 139 81 140 /** Allows access wizard from base part. */141 virtual UIWizard *wizardImp() const /* override */ { return UIWizardPage::wizard(); }142 143 82 /** Handles translation event. */ 144 virtual void retranslateUi() /* override */;83 virtual void retranslateUi() /* override final */; 145 84 146 85 /** Performs page initialization. */ 147 virtual void initializePage() /* override */;86 virtual void initializePage() /* override final */; 148 87 149 88 /** Returns whether page is complete. */ 150 virtual bool isComplete() const /* override */;89 virtual bool isComplete() const /* override final */; 151 90 152 91 /** Performs page validation. */ 153 virtual bool validatePage() /* override */;92 virtual bool validatePage() /* override final */; 154 93 155 94 private slots: 156 95 157 /** Handles change in sourcecombo-box. */158 void sltHandle SourceChange();96 /** Handles change in provider combo-box. */ 97 void sltHandleProviderComboChange(); 159 98 160 99 /** Handles change in profile combo-box. */ 161 100 void sltHandleProfileComboChange(); 162 163 101 /** Handles profile tool-button click. */ 164 102 void sltHandleProfileButtonClick(); 165 103 104 /** Handles change in instance list. */ 105 void sltHandleSourceInstanceChange(); 106 166 107 private: 108 109 /** Defines short provider name. */ 110 void setShortProviderName(const QString &strShortProviderName); 111 /** Returns profile name. */ 112 QString shortProviderName() const; 113 114 /** Defines profile name. */ 115 void setProfileName(const QString &strProfileName); 116 /** Returns profile name. */ 117 QString profileName() const; 118 119 /** Defines Cloud @a comClient object. */ 120 void setClient(const CCloudClient &comClient); 121 /** Returns Cloud Client object. */ 122 CCloudClient client() const; 123 124 /** Defines @a instanceIds. */ 125 void setInstanceIds(const QStringList &instanceIds); 126 /** Returns instance IDs. */ 127 QStringList instanceIds() const; 128 129 /** Updates provider. */ 130 void updateProvider(); 131 /** Updates profile. */ 132 void updateProfile(); 133 /** Updates source instance. */ 134 void updateSourceInstance(); 167 135 168 136 /** Holds the main label instance. */ 169 137 QIRichTextLabel *m_pLabelMain; 138 139 /** Holds the provider layout instance. */ 140 QGridLayout *m_pProviderLayout; 141 /** Holds the provider type label instance. */ 142 QLabel *m_pProviderLabel; 143 /** Holds the provider type combo-box instance. */ 144 QIComboBox *m_pProviderComboBox; 145 170 146 /** Holds the description label instance. */ 171 147 QIRichTextLabel *m_pLabelDescription; 148 149 /** Holds the options layout instance. */ 150 QGridLayout *m_pOptionsLayout; 151 /** Holds the profile label instance. */ 152 QLabel *m_pProfileLabel; 153 /** Holds the profile combo-box instance. */ 154 QIComboBox *m_pProfileComboBox; 155 /** Holds the profile management tool-button instance. */ 156 QIToolButton *m_pProfileToolButton; 157 /** Holds the source instance label instance. */ 158 QLabel *m_pSourceInstanceLabel; 159 /** Holds the source instance list instance. */ 160 QListWidget *m_pSourceInstanceList; 172 161 }; 173 162 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/addcloudvm/UIWizardAddCloudVMPageExpert.cpp
r86687 r89999 5 5 6 6 /* 7 * Copyright (C) 2009-202 0Oracle Corporation7 * Copyright (C) 2009-2021 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 26 26 #include "QIComboBox.h" 27 27 #include "QIToolButton.h" 28 #include "UICloudNetworkingStuff.h" 28 29 #include "UIIconPool.h" 29 30 #include "UIMessageCenter.h" … … 33 34 #include "UIWizardAddCloudVMPageExpert.h" 34 35 36 /* Namespaces: */ 37 using namespace UIWizardAddCloudVMPage1; 38 35 39 36 40 UIWizardAddCloudVMPageExpert::UIWizardAddCloudVMPageExpert() 37 : m_pCntSource(0) 38 { 39 /* Create main layout: */ 40 QHBoxLayout *pMainLayout = new QHBoxLayout(this); 41 if (pMainLayout) 41 : m_pCntProvider(0) 42 , m_pProviderLayout(0) 43 , m_pProviderLabel(0) 44 , m_pProviderComboBox(0) 45 , m_pOptionsLayout(0) 46 , m_pProfileLabel(0) 47 , m_pProfileComboBox(0) 48 , m_pProfileToolButton(0) 49 , m_pSourceInstanceLabel(0) 50 , m_pSourceInstanceList(0) 51 { 52 /* Prepare main layout: */ 53 QHBoxLayout *pLayoutMain = new QHBoxLayout(this); 54 if (pLayoutMain) 42 55 { 43 /* Create sourcecontainer: */44 m_pCnt Source= new QGroupBox(this);45 if (m_pCnt Source)56 /* Prepare provider container: */ 57 m_pCntProvider = new QGroupBox(this); 58 if (m_pCntProvider) 46 59 { 47 /* Create sourcelayout: */48 m_p SourceLayout = new QGridLayout(m_pCntSource);49 if (m_p SourceLayout)60 /* Prepare provider layout: */ 61 m_pProviderLayout = new QGridLayout(m_pCntProvider); 62 if (m_pProviderLayout) 50 63 { 51 /* Create source selector: */ 52 m_pSourceComboBox = new QIComboBox(m_pCntSource); 53 if (m_pSourceComboBox) 64 /* Prepare provider selector: */ 65 m_pProviderComboBox = new QIComboBox(m_pCntProvider); 66 if (m_pProviderComboBox) 67 m_pProviderLayout->addWidget(m_pProviderComboBox, 0, 0); 68 69 /* Prepare options layout: */ 70 m_pOptionsLayout = new QGridLayout; 71 if (m_pOptionsLayout) 54 72 { 55 /* Add into layout: */ 56 m_pSourceLayout->addWidget(m_pSourceComboBox, 0, 0); 57 } 58 59 /* Create cloud container layout: */ 60 m_pCloudContainerLayout = new QGridLayout; 61 if (m_pCloudContainerLayout) 62 { 63 m_pCloudContainerLayout->setContentsMargins(0, 0, 0, 0); 64 m_pCloudContainerLayout->setRowStretch(1, 1); 65 66 /* Create sub-layout: */ 73 m_pOptionsLayout->setContentsMargins(0, 0, 0, 0); 74 m_pOptionsLayout->setRowStretch(1, 1); 75 76 /* Prepare sub-layout: */ 67 77 QHBoxLayout *pSubLayout = new QHBoxLayout; 68 78 if (pSubLayout) … … 71 81 pSubLayout->setSpacing(1); 72 82 73 /* Create profile combo-box: */74 m_pProfileComboBox = new QIComboBox(m_pCnt Source);83 /* Prepare profile combo-box: */ 84 m_pProfileComboBox = new QIComboBox(m_pCntProvider); 75 85 if (m_pProfileComboBox) 76 {77 /* Add into layout: */78 86 pSubLayout->addWidget(m_pProfileComboBox); 79 } 80 /* Create profile tool-button: */81 m_pProfileToolButton = new QIToolButton(m_pCnt Source);87 88 /* Prepare profile tool-button: */ 89 m_pProfileToolButton = new QIToolButton(m_pCntProvider); 82 90 if (m_pProfileToolButton) 83 91 { 84 92 m_pProfileToolButton->setIcon(UIIconPool::iconSet(":/cloud_profile_manager_16px.png", 85 93 ":/cloud_profile_manager_disabled_16px.png")); 86 87 /* Add into layout: */88 94 pSubLayout->addWidget(m_pProfileToolButton); 89 95 } 90 96 91 97 /* Add into layout: */ 92 m_p CloudContainerLayout->addLayout(pSubLayout, 0, 0);98 m_pOptionsLayout->addLayout(pSubLayout, 0, 0); 93 99 } 94 100 95 /* Create profile instances table: */96 m_p ProfileInstanceList = new QListWidget(m_pCntSource);97 if (m_p ProfileInstanceList)101 /* Prepare source instances table: */ 102 m_pSourceInstanceList = new QListWidget(m_pCntProvider); 103 if (m_pSourceInstanceList) 98 104 { 99 const QFontMetrics fm(m_pProfileInstanceList->font()); 105 /* Make source image list fit 50 symbols 106 * horizontally and 8 lines vertically: */ 107 const QFontMetrics fm(m_pSourceInstanceList->font()); 100 108 const int iFontWidth = fm.width('x'); 101 109 const int iTotalWidth = 50 * iFontWidth; 102 110 const int iFontHeight = fm.height(); 103 const int iTotalHeight = 4 * iFontHeight; 104 m_pProfileInstanceList->setMinimumSize(QSize(iTotalWidth, iTotalHeight)); 105 //m_pProfileInstanceList->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 106 m_pProfileInstanceList->setAlternatingRowColors(true); 107 m_pProfileInstanceList->setSelectionMode(QAbstractItemView::ExtendedSelection); 111 const int iTotalHeight = 8 * iFontHeight; 112 m_pSourceInstanceList->setMinimumSize(QSize(iTotalWidth, iTotalHeight)); 113 m_pSourceInstanceList->setAlternatingRowColors(true); 114 m_pSourceInstanceList->setSelectionMode(QAbstractItemView::ExtendedSelection); 108 115 109 116 /* Add into layout: */ 110 m_p CloudContainerLayout->addWidget(m_pProfileInstanceList, 1, 0);117 m_pOptionsLayout->addWidget(m_pSourceInstanceList, 1, 0); 111 118 } 112 119 113 120 /* Add into layout: */ 114 m_p SourceLayout->addLayout(m_pCloudContainerLayout, 1, 0);121 m_pProviderLayout->addLayout(m_pOptionsLayout, 1, 0); 115 122 } 116 123 } 117 124 118 125 /* Add into layout: */ 119 p MainLayout->addWidget(m_pCntSource);126 pLayoutMain->addWidget(m_pCntProvider); 120 127 } 121 128 } … … 123 130 /* Setup connections: */ 124 131 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileRegistered, 125 this, &UIWizardAddCloudVMPageExpert::sltHandle SourceChange);132 this, &UIWizardAddCloudVMPageExpert::sltHandleProviderComboChange); 126 133 connect(gVBoxEvents, &UIVirtualBoxEventHandler::sigCloudProfileChanged, 127 this, &UIWizardAddCloudVMPageExpert::sltHandle SourceChange);128 connect(m_p SourceComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::activated),129 this, &UIWizardAddCloudVMPageExpert::sltHandle SourceChange);134 this, &UIWizardAddCloudVMPageExpert::sltHandleProviderComboChange); 135 connect(m_pProviderComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::activated), 136 this, &UIWizardAddCloudVMPageExpert::sltHandleProviderComboChange); 130 137 connect(m_pProfileComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::currentIndexChanged), 131 138 this, &UIWizardAddCloudVMPageExpert::sltHandleProfileComboChange); 132 139 connect(m_pProfileToolButton, &QIToolButton::clicked, 133 140 this, &UIWizardAddCloudVMPageExpert::sltHandleProfileButtonClick); 134 connect(m_p ProfileInstanceList, &QListWidget::currentRowChanged,141 connect(m_pSourceInstanceList, &QListWidget::currentRowChanged, 135 142 this, &UIWizardAddCloudVMPageExpert::completeChanged); 136 137 /* Register fields: */138 registerField("source", this, "source");139 registerField("profileName", this, "profileName");140 registerField("instanceIds", this, "instanceIds");141 143 } 142 144 … … 144 146 { 145 147 /* Translate source container: */ 146 m_pCnt Source->setTitle(UIWizardAddCloudVM::tr("Source"));148 m_pCntProvider->setTitle(UIWizardAddCloudVM::tr("Source")); 147 149 148 150 /* Translate profile stuff: */ … … 151 153 /* Translate received values of Source combo-box. 152 154 * We are enumerating starting from 0 for simplicity: */ 153 for (int i = 0; i < m_p SourceComboBox->count(); ++i)155 for (int i = 0; i < m_pProviderComboBox->count(); ++i) 154 156 { 155 m_p SourceComboBox->setItemText(i, m_pSourceComboBox->itemData(i, SourceData_Name).toString());156 m_p SourceComboBox->setItemData(i, UIWizardAddCloudVM::tr("Add VM from cloud service provider."), Qt::ToolTipRole);157 m_pProviderComboBox->setItemText(i, m_pProviderComboBox->itemData(i, ProviderData_Name).toString()); 158 m_pProviderComboBox->setItemData(i, UIWizardAddCloudVM::tr("Add VM from cloud service provider."), Qt::ToolTipRole); 157 159 } 158 160 159 161 /* Update tool-tips: */ 160 update SourceComboToolTip();162 updateComboToolTip(m_pProviderComboBox); 161 163 } 162 164 163 165 void UIWizardAddCloudVMPageExpert::initializePage() 164 166 { 165 /* If wasn't polished yet: */ 166 if (!UIWizardAddCloudVMPage1::m_fPolished) 167 { 168 /* Populate sources: */ 169 populateSources(); 170 /* Choose one of them, asynchronously: */ 171 QMetaObject::invokeMethod(this, "sltHandleSourceChange", Qt::QueuedConnection); 172 UIWizardAddCloudVMPage1::m_fPolished = true; 173 } 174 175 /* Translate page: */ 167 /* Populate providers: */ 168 populateProviders(m_pProviderComboBox); 169 /* Translate providers: */ 176 170 retranslateUi(); 171 /* Fetch it, asynchronously: */ 172 QMetaObject::invokeMethod(this, "sltHandleProviderComboChange", Qt::QueuedConnection); 173 /* Make image list focused by default: */ 174 m_pSourceInstanceList->setFocus(); 177 175 } 178 176 … … 184 182 /* Make sure client is not NULL and 185 183 * at least one instance is selected: */ 186 fResult = UIWizardAddCloudVMPage1::client().isNotNull()187 && !UIWizardAddCloudVMPage1::instanceIds().isEmpty();184 fResult = client().isNotNull() 185 && !instanceIds().isEmpty(); 188 186 189 187 /* Return result: */ … … 196 194 bool fResult = true; 197 195 198 /* Lock finish button: */199 startProcessing();200 201 196 /* Try to add cloud VMs: */ 202 197 fResult = qobject_cast<UIWizardAddCloudVM*>(wizard())->addCloudVMs(); 203 198 204 /* Unlock finish button: */205 endProcessing();206 207 199 /* Return result: */ 208 200 return fResult; 209 201 } 210 202 211 void UIWizardAddCloudVMPageExpert::sltHandleSourceChange() 212 { 213 /* Update tool-tip: */ 214 updateSourceComboToolTip(); 215 216 /* Make instance list focused by default: */ 217 m_pProfileInstanceList->setFocus(); 218 219 /* Refresh required settings: */ 220 populateProfiles(); 221 populateProfile(); 222 populateProfileInstances(); 203 void UIWizardAddCloudVMPageExpert::sltHandleProviderComboChange() 204 { 205 updateProvider(); 223 206 emit completeChanged(); 224 207 } … … 226 209 void UIWizardAddCloudVMPageExpert::sltHandleProfileComboChange() 227 210 { 228 /* Refresh required settings: */ 229 populateProfile(); 230 populateProfileInstances(); 211 updateProfile(); 231 212 emit completeChanged(); 232 213 } … … 234 215 void UIWizardAddCloudVMPageExpert::sltHandleProfileButtonClick() 235 216 { 236 /* Open Cloud Profile Manager: */237 217 if (gpManager) 238 218 gpManager->openCloudProfileManager(); 239 219 } 220 221 void UIWizardAddCloudVMPageExpert::sltHandleSourceInstanceChange() 222 { 223 updateSourceInstance(); 224 emit completeChanged(); 225 } 226 227 void UIWizardAddCloudVMPageExpert::setShortProviderName(const QString &strShortProviderName) 228 { 229 qobject_cast<UIWizardAddCloudVM*>(wizard())->setShortProviderName(strShortProviderName); 230 } 231 232 QString UIWizardAddCloudVMPageExpert::shortProviderName() const 233 { 234 return qobject_cast<UIWizardAddCloudVM*>(wizard())->shortProviderName(); 235 } 236 237 void UIWizardAddCloudVMPageExpert::setProfileName(const QString &strProfileName) 238 { 239 qobject_cast<UIWizardAddCloudVM*>(wizard())->setProfileName(strProfileName); 240 } 241 242 QString UIWizardAddCloudVMPageExpert::profileName() const 243 { 244 return qobject_cast<UIWizardAddCloudVM*>(wizard())->profileName(); 245 } 246 247 void UIWizardAddCloudVMPageExpert::setClient(const CCloudClient &comClient) 248 { 249 qobject_cast<UIWizardAddCloudVM*>(wizard())->setClient(comClient); 250 } 251 252 CCloudClient UIWizardAddCloudVMPageExpert::client() const 253 { 254 return qobject_cast<UIWizardAddCloudVM*>(wizard())->client(); 255 } 256 257 void UIWizardAddCloudVMPageExpert::setInstanceIds(const QStringList &instanceIds) 258 { 259 qobject_cast<UIWizardAddCloudVM*>(wizard())->setInstanceIds(instanceIds); 260 } 261 262 QStringList UIWizardAddCloudVMPageExpert::instanceIds() const 263 { 264 return qobject_cast<UIWizardAddCloudVM*>(wizard())->instanceIds(); 265 } 266 267 void UIWizardAddCloudVMPageExpert::updateProvider() 268 { 269 updateComboToolTip(m_pProviderComboBox); 270 setShortProviderName(m_pProviderComboBox->currentData(ProviderData_ShortName).toString()); 271 CCloudProvider comCloudProvider = cloudProviderByShortName(shortProviderName(), wizard()); 272 populateProfiles(m_pProfileComboBox, comCloudProvider); 273 updateProfile(); 274 } 275 276 void UIWizardAddCloudVMPageExpert::updateProfile() 277 { 278 setProfileName(m_pProfileComboBox->currentData(ProfileData_Name).toString()); 279 setClient(cloudClientByName(shortProviderName(), profileName(), wizard())); 280 populateProfileInstances(m_pSourceInstanceList, client()); 281 updateSourceInstance(); 282 } 283 284 void UIWizardAddCloudVMPageExpert::updateSourceInstance() 285 { 286 setInstanceIds(currentListWidgetData(m_pSourceInstanceList)); 287 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/addcloudvm/UIWizardAddCloudVMPageExpert.h
r86346 r89999 5 5 6 6 /* 7 * Copyright (C) 2009-202 0Oracle Corporation7 * Copyright (C) 2009-2021 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 28 28 class QGroupBox; 29 29 30 /** UI WizardPage extension for UIWizardAddCloudVMPage1. */31 class UIWizardAddCloudVMPageExpert : public UIWizardPage, 32 public UIWizardAddCloudVMPage1 30 /** UINativeWizardPage extension for Expert page of the Add Cloud VM wizard, 31 * based on UIWizardAddCloudVMPage1 namespace functions. */ 32 class UIWizardAddCloudVMPageExpert : public UINativeWizardPage 33 33 { 34 34 Q_OBJECT; 35 Q_PROPERTY(QString source READ source);36 Q_PROPERTY(QString profileName READ profileName);37 Q_PROPERTY(QStringList instanceIds READ instanceIds);38 35 39 36 public: … … 44 41 protected: 45 42 46 /** Allows access wizard from base part. */47 virtual UIWizard *wizardImp() const /* override */ { return UIWizardPage::wizard(); }48 49 43 /** Handles translation event. */ 50 virtual void retranslateUi() /* override */;44 virtual void retranslateUi() /* override final */; 51 45 52 46 /** Performs page initialization. */ 53 virtual void initializePage() /* override */;47 virtual void initializePage() /* override final */; 54 48 55 49 /** Returns whether page is complete. */ 56 virtual bool isComplete() const /* override */;50 virtual bool isComplete() const /* override final */; 57 51 58 52 /** Performs page validation. */ 59 virtual bool validatePage() /* override */;53 virtual bool validatePage() /* override final */; 60 54 61 55 private slots: 62 56 63 /** Handles change in sourcecombo-box. */64 void sltHandle SourceChange();57 /** Handles change in provider combo-box. */ 58 void sltHandleProviderComboChange(); 65 59 66 60 /** Handles change in profile combo-box. */ 67 61 void sltHandleProfileComboChange(); 68 69 62 /** Handles profile tool-button click. */ 70 63 void sltHandleProfileButtonClick(); 71 64 65 /** Handles change in instance list. */ 66 void sltHandleSourceInstanceChange(); 67 72 68 private: 73 69 74 /** Holds the source container instance. */ 75 QGroupBox *m_pCntSource; 70 /** Defines short provider name. */ 71 void setShortProviderName(const QString &strShortProviderName); 72 /** Returns profile name. */ 73 QString shortProviderName() const; 74 75 /** Defines profile name. */ 76 void setProfileName(const QString &strProfileName); 77 /** Returns profile name. */ 78 QString profileName() const; 79 80 /** Defines Cloud @a comClient object. */ 81 void setClient(const CCloudClient &comClient); 82 /** Returns Cloud Client object. */ 83 CCloudClient client() const; 84 85 /** Defines @a instanceIds. */ 86 void setInstanceIds(const QStringList &instanceIds); 87 /** Returns instance IDs. */ 88 QStringList instanceIds() const; 89 90 /** Updates provider. */ 91 void updateProvider(); 92 /** Updates profile. */ 93 void updateProfile(); 94 /** Updates source instance. */ 95 void updateSourceInstance(); 96 97 /** Holds the provider container instance. */ 98 QGroupBox *m_pCntProvider; 99 100 /** Holds the provider layout instance. */ 101 QGridLayout *m_pProviderLayout; 102 /** Holds the provider type label instance. */ 103 QLabel *m_pProviderLabel; 104 /** Holds the provider type combo-box instance. */ 105 QIComboBox *m_pProviderComboBox; 106 107 /** Holds the options layout instance. */ 108 QGridLayout *m_pOptionsLayout; 109 /** Holds the profile label instance. */ 110 QLabel *m_pProfileLabel; 111 /** Holds the profile combo-box instance. */ 112 QIComboBox *m_pProfileComboBox; 113 /** Holds the profile management tool-button instance. */ 114 QIToolButton *m_pProfileToolButton; 115 /** Holds the source instance label instance. */ 116 QLabel *m_pSourceInstanceLabel; 117 /** Holds the source instance list instance. */ 118 QListWidget *m_pSourceInstanceList; 76 119 }; 77 120
Note:
See TracChangeset
for help on using the changeset viewer.