- Timestamp:
- Apr 24, 2019 3:25:52 PM (6 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageExpert.cpp
r78063 r78276 19 19 #include <QFileInfo> 20 20 #include <QGroupBox> 21 #include <QHeaderView> 22 #include <QLabel> 23 #include <QListWidget> 24 #include <QStackedLayout> 25 #include <QTableWidget> 21 26 #include <QVBoxLayout> 22 27 23 28 /* GUI includes: */ 29 #include "QIComboBox.h" 30 #include "QIToolButton.h" 24 31 #include "VBoxGlobal.h" 25 32 #include "UIApplianceImportEditorWidget.h" 26 33 #include "UIEmptyFilePathSelector.h" 34 #include "UIIconPool.h" 35 #include "UIVirtualBoxManager.h" 27 36 #include "UIWizardImportApp.h" 28 37 #include "UIWizardImportAppPageExpert.h" … … 31 40 UIWizardImportAppPageExpert::UIWizardImportAppPageExpert(bool fImportFromOCIByDefault, const QString &strFileName) 32 41 : UIWizardImportAppPage1(fImportFromOCIByDefault) 33 , m_p ApplianceCnt(0)42 , m_pCntSource(0) 34 43 , m_pSettingsCnt(0) 35 44 { 36 45 /* Create main layout: */ 37 QVBoxLayout *pMainLayout = new QVBoxLayout(this); 46 QHBoxLayout *pMainLayout = new QHBoxLayout(this); 47 if (pMainLayout) 38 48 { 39 /* Create appliance container: */ 40 m_pApplianceCnt = new QGroupBox(this); 49 /* Create source container: */ 50 m_pCntSource = new QGroupBox(this); 51 if (m_pCntSource) 41 52 { 42 /* Create appliance container layout: */ 43 QVBoxLayout *pApplianceCntLayout = new QVBoxLayout(m_pApplianceCnt); 53 /* Create source layout: */ 54 m_pSourceLayout = new QGridLayout(m_pCntSource); 55 if (m_pSourceLayout) 44 56 { 45 /* Create file-path selector: */ 46 m_pFileSelector = new UIEmptyFilePathSelector(m_pApplianceCnt); 57 /* Create source selector: */ 58 m_pSourceComboBox = new QIComboBox(m_pCntSource); 59 if (m_pSourceComboBox) 47 60 { 48 m_pFileSelector->setHomeDir(vboxGlobal().documentsPath());49 m_pFileSelector->setMode(UIEmptyFilePathSelector::Mode_File_Open);50 m_pFileSelector->setButtonPosition(UIEmptyFilePathSelector::RightPosition);51 m_pFileSelector->setEditable(true);52 m_pFileSelector->setPath(strFileName);53 54 61 /* Add into layout: */ 55 pApplianceCntLayout->addWidget(m_pFileSelector); 62 m_pSourceLayout->addWidget(m_pSourceComboBox, 0, 0); 63 } 64 65 /* Create stacked layout: */ 66 m_pStackedLayout = new QStackedLayout(m_pCntSource); 67 if (m_pStackedLayout) 68 { 69 /* Create local container: */ 70 QWidget *pLocalContainer = new QWidget(m_pCntSource); 71 if (pLocalContainer) 72 { 73 /* Create local container layout: */ 74 m_pLocalContainerLayout = new QGridLayout(pLocalContainer); 75 if (m_pLocalContainerLayout) 76 { 77 m_pLocalContainerLayout->setContentsMargins(0, 0, 0, 0); 78 m_pLocalContainerLayout->setRowStretch(2, 1); 79 80 /* Create file-path selector: */ 81 m_pFileSelector = new UIEmptyFilePathSelector(pLocalContainer); 82 if (m_pFileSelector) 83 { 84 m_pFileSelector->setHomeDir(vboxGlobal().documentsPath()); 85 m_pFileSelector->setMode(UIEmptyFilePathSelector::Mode_File_Open); 86 m_pFileSelector->setButtonPosition(UIEmptyFilePathSelector::RightPosition); 87 m_pFileSelector->setEditable(true); 88 89 /* Add into layout: */ 90 m_pLocalContainerLayout->addWidget(m_pFileSelector, 0, 0); 91 } 92 } 93 94 /* Add into layout: */ 95 m_pStackedLayout->addWidget(pLocalContainer); 96 } 97 98 /* Create cloud container: */ 99 QWidget *pCloudContainer = new QWidget(m_pCntSource); 100 if (pCloudContainer) 101 { 102 /* Create cloud container layout: */ 103 m_pCloudContainerLayout = new QGridLayout(pCloudContainer); 104 if (m_pCloudContainerLayout) 105 { 106 m_pCloudContainerLayout->setContentsMargins(0, 0, 0, 0); 107 m_pCloudContainerLayout->setRowStretch(3, 1); 108 109 /* Create sub-layout: */ 110 QHBoxLayout *pSubLayout = new QHBoxLayout; 111 if (pSubLayout) 112 { 113 pSubLayout->setContentsMargins(0, 0, 0, 0); 114 pSubLayout->setSpacing(1); 115 116 /* Create account combo-box: */ 117 m_pAccountComboBox = new QComboBox(pCloudContainer); 118 if (m_pAccountComboBox) 119 { 120 /* Add into layout: */ 121 pSubLayout->addWidget(m_pAccountComboBox); 122 } 123 124 /* Create account tool-button: */ 125 m_pAccountToolButton = new QIToolButton(pCloudContainer); 126 if (m_pAccountToolButton) 127 { 128 m_pAccountToolButton->setIcon(UIIconPool::iconSet(":/cloud_profile_manager_16px.png", 129 ":/cloud_profile_manager_disabled_16px.png")); 130 131 /* Add into layout: */ 132 pSubLayout->addWidget(m_pAccountToolButton); 133 } 134 135 /* Add into layout: */ 136 m_pCloudContainerLayout->addLayout(pSubLayout, 0, 0); 137 } 138 139 /* Create profile property table: */ 140 m_pAccountPropertyTable = new QTableWidget(pCloudContainer); 141 if (m_pAccountPropertyTable) 142 { 143 const QFontMetrics fm(m_pAccountPropertyTable->font()); 144 const int iFontWidth = fm.width('x'); 145 const int iTotalWidth = 50 * iFontWidth; 146 const int iFontHeight = fm.height(); 147 const int iTotalHeight = 4 * iFontHeight; 148 m_pAccountPropertyTable->setMinimumSize(QSize(iTotalWidth, iTotalHeight)); 149 // m_pAccountPropertyTable->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 150 m_pAccountPropertyTable->setAlternatingRowColors(true); 151 m_pAccountPropertyTable->horizontalHeader()->setVisible(false); 152 m_pAccountPropertyTable->verticalHeader()->setVisible(false); 153 m_pAccountPropertyTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); 154 155 /* Add into layout: */ 156 m_pCloudContainerLayout->addWidget(m_pAccountPropertyTable, 1, 0); 157 } 158 159 /* Create profile instances table: */ 160 m_pAccountInstanceList = new QListWidget(pCloudContainer); 161 if (m_pAccountInstanceList) 162 { 163 const QFontMetrics fm(m_pAccountInstanceList->font()); 164 const int iFontWidth = fm.width('x'); 165 const int iTotalWidth = 50 * iFontWidth; 166 const int iFontHeight = fm.height(); 167 const int iTotalHeight = 4 * iFontHeight; 168 m_pAccountInstanceList->setMinimumSize(QSize(iTotalWidth, iTotalHeight)); 169 // m_pAccountInstanceList->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 170 m_pAccountInstanceList->setAlternatingRowColors(true); 171 172 /* Add into layout: */ 173 m_pCloudContainerLayout->addWidget(m_pAccountInstanceList, 2, 0); 174 } 175 } 176 177 /* Add into layout: */ 178 m_pStackedLayout->addWidget(pCloudContainer); 179 } 180 181 /* Add into layout: */ 182 m_pSourceLayout->addLayout(m_pStackedLayout, 1, 0); 56 183 } 57 184 } 58 185 59 186 /* Add into layout: */ 60 pMainLayout->addWidget(m_p ApplianceCnt);187 pMainLayout->addWidget(m_pCntSource); 61 188 } 62 189 63 190 /* Create settings container: */ 64 191 m_pSettingsCnt = new QGroupBox(this); 192 if (m_pSettingsCnt) 65 193 { 66 194 /* Create settings container layout: */ 67 QVBoxLayout *pSettingsCntLayout = new QVBoxLayout(m_pSettingsCnt); 195 m_pSettingsCntLayout = new QStackedLayout(m_pSettingsCnt); 196 if (m_pSettingsCntLayout) 68 197 { 69 /* Create appliance widget: */ 70 m_pApplianceWidget = new UIApplianceImportEditorWidget(m_pSettingsCnt); 198 /* Create appliance widget container: */ 199 QWidget *pApplianceWidgetCnt = new QWidget(m_pSettingsCnt); 200 if (pApplianceWidgetCnt) 71 201 { 72 m_pApplianceWidget->setMinimumHeight(300); 73 m_pApplianceWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); 74 m_pApplianceWidget->setFile(strFileName); 202 /* Create appliance widget layout: */ 203 QVBoxLayout *pApplianceWidgetLayout = new QVBoxLayout(pApplianceWidgetCnt); 204 if (pApplianceWidgetLayout) 205 { 206 /* Create appliance widget: */ 207 m_pApplianceWidget = new UIApplianceImportEditorWidget(pApplianceWidgetCnt); 208 if (m_pApplianceWidget) 209 { 210 m_pApplianceWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); 211 m_pApplianceWidget->setFile(strFileName); 212 213 /* Add into layout: */ 214 pApplianceWidgetLayout->addWidget(m_pApplianceWidget); 215 } 216 } 75 217 76 218 /* Add into layout: */ 77 pSettingsCntLayout->addWidget(m_pApplianceWidget); 219 m_pSettingsCntLayout->addWidget(pApplianceWidgetCnt); 220 } 221 222 /* Create form editor container: */ 223 QWidget *pFormEditorCnt = new QWidget(m_pSettingsCnt); 224 if (pFormEditorCnt) 225 { 226 /* Create form editor layout: */ 227 QVBoxLayout *pFormEditorLayout = new QVBoxLayout(pFormEditorCnt); 228 if (pFormEditorLayout) 229 { 230 /* Create form editor widget: */ 231 m_pFormEditor = new UIFormEditorWidget(pFormEditorCnt); 232 if (m_pFormEditor) 233 { 234 /* Add into layout: */ 235 pFormEditorLayout->addWidget(m_pFormEditor); 236 } 237 } 238 239 /* Add into layout: */ 240 m_pSettingsCntLayout->addWidget(pFormEditorCnt); 78 241 } 79 242 } … … 84 247 } 85 248 249 /* Populate sources: */ 250 populateSources(); 251 /* Populate accounts: */ 252 populateAccounts(); 253 /* Populate account properties: */ 254 populateAccountProperties(); 255 /* Populate account instances: */ 256 populateAccountInstances(); 257 /* Populate form properties: */ 258 populateFormProperties(); 259 populateFormPropertiesTable(); 260 86 261 /* Setup connections: */ 87 connect(m_pFileSelector, &UIEmptyFilePathSelector::pathChanged, this, &UIWizardImportAppPageExpert::sltFilePathChangeHandler); 262 if (gpManager) 263 connect(gpManager, &UIVirtualBoxManager::sigCloudProfileManagerChange, 264 this, &UIWizardImportAppPageExpert::sltHandleSourceChange); 265 connect(m_pSourceComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::activated), 266 this, &UIWizardImportAppPageExpert::sltHandleSourceChange); 267 connect(m_pFileSelector, &UIEmptyFilePathSelector::pathChanged, 268 this, &UIWizardImportAppPageExpert::sltFilePathChangeHandler); 269 connect(m_pAccountComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), 270 this, &UIWizardImportAppPageExpert::sltHandleAccountComboChange); 271 connect(m_pAccountToolButton, &QIToolButton::clicked, 272 this, &UIWizardImportAppPageExpert::sltHandleAccountButtonClick); 273 connect(m_pAccountInstanceList, &QListWidget::currentRowChanged, 274 this, &UIWizardImportAppPageExpert::completeChanged); 88 275 89 276 /* Register classes: */ 90 277 qRegisterMetaType<ImportAppliancePointer>(); 91 278 /* Register fields: */ 279 registerField("source", this, "source"); 280 registerField("isSourceCloudOne", this, "isSourceCloudOne"); 281 registerField("profile", this, "profile"); 282 registerField("vsdForm", this, "vsdForm"); 283 registerField("machineId", this, "machineId"); 92 284 registerField("applianceWidget", this, "applianceWidget"); 285 } 286 287 bool UIWizardImportAppPageExpert::event(QEvent *pEvent) 288 { 289 /* Handle known event types: */ 290 switch (pEvent->type()) 291 { 292 case QEvent::Show: 293 case QEvent::Resize: 294 { 295 /* Adjust profile property table: */ 296 adjustAccountPropertyTable(); 297 break; 298 } 299 default: 300 break; 301 } 302 303 /* Call to base-class: */ 304 return UIWizardPage::event(pEvent); 305 } 306 307 void UIWizardImportAppPageExpert::retranslateUi() 308 { 309 /* Translate appliance container: */ 310 m_pCntSource->setTitle(UIWizardImportApp::tr("Source")); 311 312 /* Translate hardcoded values of Source combo-box: */ 313 m_pSourceComboBox->setItemText(0, UIWizardImportApp::tr("Local File System")); 314 m_pSourceComboBox->setItemData(0, UIWizardImportApp::tr("Import from local file system."), Qt::ToolTipRole); 315 /* Translate received values of Source combo-box. 316 * We are enumerating starting from 0 for simplicity: */ 317 for (int i = 0; i < m_pSourceComboBox->count(); ++i) 318 if (isSourceCloudOne(i)) 319 { 320 m_pSourceComboBox->setItemText(i, m_pSourceComboBox->itemData(i, SourceData_Name).toString()); 321 m_pSourceComboBox->setItemData(i, UIWizardImportApp::tr("Import from cloud service provider."), Qt::ToolTipRole); 322 } 323 324 /* Translate file selector: */ 325 m_pFileSelector->setChooseButtonToolTip(UIWizardImportApp::tr("Choose a virtual appliance file to import...")); 326 m_pFileSelector->setFileDialogTitle(UIWizardImportApp::tr("Please choose a virtual appliance file to import")); 327 m_pFileSelector->setFileFilters(UIWizardImportApp::tr("Open Virtualization Format (%1)").arg("*.ova *.ovf")); 328 329 /* Translate settings container: */ 330 m_pSettingsCnt->setTitle(UIWizardImportApp::tr("Settings")); 331 332 /* Update page appearance: */ 333 updatePageAppearance(); 334 335 /* Update tool-tips: */ 336 updateSourceComboToolTip(); 337 updateAccountPropertyTableToolTips(); 338 } 339 340 void UIWizardImportAppPageExpert::initializePage() 341 { 342 /* Translate page: */ 343 retranslateUi(); 344 } 345 346 bool UIWizardImportAppPageExpert::isComplete() const 347 { 348 bool fResult = true; 349 350 /* Check appliance settings: */ 351 if (fResult) 352 { 353 const bool fOVF = !isSourceCloudOne(); 354 // const bool fCSP = !fOVF; 355 356 fResult = ( fOVF 357 && VBoxGlobal::hasAllowedExtension(m_pFileSelector->path().toLower(), OVFFileExts) 358 && QFile::exists(m_pFileSelector->path()) 359 && m_pApplianceWidget->isValid()) 360 // || ( fCSP 361 // && !m_comCloudProfile.isNull() 362 // && !m_comCloudClient.isNull() 363 // && !machineId().isNull()) 364 ; 365 } 366 367 return fResult; 368 } 369 370 bool UIWizardImportAppPageExpert::validatePage() 371 { 372 /* Initial result: */ 373 bool fResult = true; 374 375 /* Lock finish button: */ 376 startProcessing(); 377 378 /* Try to import appliance: */ 379 if (fResult) 380 fResult = qobject_cast<UIWizardImportApp*>(wizard())->importAppliance(); 381 382 /* Unlock finish button: */ 383 endProcessing(); 384 385 /* Return result: */ 386 return fResult; 387 } 388 389 void UIWizardImportAppPageExpert::updatePageAppearance() 390 { 391 /* Call to base-class: */ 392 UIWizardImportAppPage1::updatePageAppearance(); 393 UIWizardImportAppPage2::updatePageAppearance(); 394 395 /* Update page appearance according to chosen storage-type: */ 396 if (isSourceCloudOne()) 397 m_pAccountInstanceList->setFocus(); 398 else 399 m_pFileSelector->setFocus(); 400 } 401 402 void UIWizardImportAppPageExpert::sltHandleSourceChange() 403 { 404 /* Update tool-tip: */ 405 updateSourceComboToolTip(); 406 407 /* Refresh required settings: */ 408 updatePageAppearance(); 409 populateAccounts(); 410 populateAccountProperties(); 411 populateAccountInstances(); 412 populateFormProperties(); 413 populateFormPropertiesTable(); 414 emit completeChanged(); 93 415 } 94 416 … … 106 428 } 107 429 108 void UIWizardImportAppPageExpert::retranslateUi() 109 { 110 /* Translate widgets: */ 111 m_pApplianceCnt->setTitle(UIWizardImportApp::tr("Appliance to import")); 112 m_pFileSelector->setChooseButtonToolTip(UIWizardImportApp::tr("Choose a virtual appliance file to import...")); 113 m_pFileSelector->setFileDialogTitle(UIWizardImportApp::tr("Please choose a virtual appliance file to import")); 114 m_pFileSelector->setFileFilters(UIWizardImportApp::tr("Open Virtualization Format (%1)").arg("*.ova *.ovf")); 115 m_pSettingsCnt->setTitle(UIWizardImportApp::tr("Appliance settings")); 116 } 117 118 void UIWizardImportAppPageExpert::initializePage() 119 { 120 retranslateUi(); 121 } 122 123 bool UIWizardImportAppPageExpert::isComplete() const 124 { 125 /* Make sure appliance file has allowed extension and exists and appliance widget is valid: */ 126 return VBoxGlobal::hasAllowedExtension(m_pFileSelector->path().toLower(), OVFFileExts) 127 && QFile::exists(m_pFileSelector->path()) 128 && m_pApplianceWidget->isValid(); 129 } 130 131 bool UIWizardImportAppPageExpert::validatePage() 132 { 133 /* Initial result: */ 134 bool fResult = true; 135 136 /* Lock finish button: */ 137 startProcessing(); 138 139 /* Try to import appliance: */ 140 if (fResult) 141 fResult = qobject_cast<UIWizardImportApp*>(wizard())->importAppliance(); 142 143 /* Unlock finish button: */ 144 endProcessing(); 145 146 /* Return result: */ 147 return fResult; 148 } 430 void UIWizardImportAppPageExpert::sltHandleAccountComboChange() 431 { 432 /* Refresh required settings: */ 433 populateAccountProperties(); 434 populateAccountInstances(); 435 populateFormProperties(); 436 populateFormPropertiesTable(); 437 emit completeChanged(); 438 } 439 440 void UIWizardImportAppPageExpert::sltHandleAccountButtonClick() 441 { 442 /* Open Cloud Profile Manager: */ 443 if (gpManager) 444 gpManager->openCloudProfileManager(); 445 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageExpert.h
r78063 r78276 35 35 { 36 36 Q_OBJECT; 37 Q_PROPERTY(QString source READ source WRITE setSource); 38 Q_PROPERTY(bool isSourceCloudOne READ isSourceCloudOne); 39 Q_PROPERTY(CCloudProfile profile READ profile); 40 Q_PROPERTY(CVirtualSystemDescriptionForm vsdForm READ vsdForm); 41 Q_PROPERTY(QString machineId READ machineId); 37 42 Q_PROPERTY(ImportAppliancePointer applianceWidget READ applianceWidget); 38 43 … … 43 48 UIWizardImportAppPageExpert(bool fImportFromOCIByDefault, const QString &strFileName); 44 49 45 pr ivate slots:50 protected: 46 51 47 /** Handles file-path change. */48 v oid sltFilePathChangeHandler();52 /** Allows to access 'field()' from base part. */ 53 virtual QVariant fieldImp(const QString &strFieldName) const /* override */ { return UIWizardPage::field(strFieldName); } 49 54 50 private: 55 /** Handle any Qt @a pEvent. */ 56 virtual bool event(QEvent *pEvent) /* override */; 51 57 52 58 /** Handles translation event. */ … … 62 68 virtual bool validatePage() /* override */; 63 69 64 /** Holds the appliance container instance. */ 65 QGroupBox *m_pApplianceCnt; 70 /** Updates page appearance. */ 71 virtual void updatePageAppearance() /* override */; 72 73 private slots: 74 75 /** Handles import source change. */ 76 void sltHandleSourceChange(); 77 78 /** Handles file-path change. */ 79 void sltFilePathChangeHandler(); 80 81 /** Handles change in account combo-box. */ 82 void sltHandleAccountComboChange(); 83 /** Handles account tool-button click. */ 84 void sltHandleAccountButtonClick(); 85 86 private: 87 88 /** Holds the source container instance. */ 89 QGroupBox *m_pCntSource; 66 90 /** Holds the settings container instance. */ 67 91 QGroupBox *m_pSettingsCnt;
Note:
See TracChangeset
for help on using the changeset viewer.