Changeset 78082 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Apr 10, 2019 11:56:38 AM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 129938
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageBasic1.cpp
r78081 r78082 18 18 /* Qt includes: */ 19 19 #include <QFileInfo> 20 #include <QHeaderView> 20 21 #include <QLabel> 21 22 #include <QStackedLayout> 23 #include <QTableWidget> 22 24 #include <QVBoxLayout> 23 25 … … 25 27 #include "QIComboBox.h" 26 28 #include "QIRichTextLabel.h" 29 #include "QIToolButton.h" 27 30 #include "VBoxGlobal.h" 28 31 #include "UIEmptyFilePathSelector.h" 32 #include "UIIconPool.h" 29 33 #include "UIMessageCenter.h" 34 #include "UIVirtualBoxManager.h" 30 35 #include "UIWizardImportApp.h" 31 36 #include "UIWizardImportAppPageBasic1.h" … … 45 50 , m_pFileSelector(0) 46 51 , m_pCloudContainerLayout(0) 52 , m_pAccountLabel(0) 53 , m_pAccountComboBox(0) 54 , m_pAccountToolButton(0) 55 , m_pAccountPropertyTable(0) 47 56 { 48 57 } … … 105 114 } 106 115 116 void UIWizardImportAppPage1::populateAccounts() 117 { 118 /* Block signals while updating: */ 119 m_pAccountComboBox->blockSignals(true); 120 121 /* Remember current item data to be able to restore it: */ 122 QString strOldData; 123 if (m_pAccountComboBox->currentIndex() != -1) 124 strOldData = m_pAccountComboBox->itemData(m_pAccountComboBox->currentIndex(), AccountData_ProfileName).toString(); 125 126 /* Clear combo initially: */ 127 m_pAccountComboBox->clear(); 128 /* Clear Cloud Provider: */ 129 m_comCloudProvider = CCloudProvider(); 130 131 /* If provider chosen: */ 132 if (!sourceId().isNull()) 133 { 134 /* (Re)initialize Cloud Provider: */ 135 m_comCloudProvider = m_comCloudProviderManager.GetProviderById(sourceId()); 136 /* Show error message if necessary: */ 137 if (!m_comCloudProviderManager.isOk()) 138 msgCenter().cannotFindCloudProvider(m_comCloudProviderManager, sourceId()); 139 else 140 { 141 /* Acquire existing profile names: */ 142 const QVector<QString> profileNames = m_comCloudProvider.GetProfileNames(); 143 /* Show error message if necessary: */ 144 if (!m_comCloudProvider.isOk()) 145 msgCenter().cannotAcquireCloudProviderParameter(m_comCloudProvider); 146 else 147 { 148 /* Iterate through existing profile names: */ 149 foreach (const QString &strProfileName, profileNames) 150 { 151 /* Skip if we have nothing to show (wtf happened?): */ 152 if (strProfileName.isEmpty()) 153 continue; 154 155 /* Compose item, fill it's data: */ 156 m_pAccountComboBox->addItem(strProfileName); 157 m_pAccountComboBox->setItemData(m_pAccountComboBox->count() - 1, strProfileName, AccountData_ProfileName); 158 } 159 } 160 } 161 162 /* Set previous/default item if possible: */ 163 int iNewIndex = -1; 164 if ( iNewIndex == -1 165 && !strOldData.isNull()) 166 iNewIndex = m_pAccountComboBox->findData(strOldData, AccountData_ProfileName); 167 if ( iNewIndex == -1 168 && m_pAccountComboBox->count() > 0) 169 iNewIndex = 0; 170 if (iNewIndex != -1) 171 m_pAccountComboBox->setCurrentIndex(iNewIndex); 172 } 173 174 /* Unblock signals after update: */ 175 m_pAccountComboBox->blockSignals(false); 176 } 177 178 void UIWizardImportAppPage1::populateAccountProperties() 179 { 180 /* Clear table initially: */ 181 m_pAccountPropertyTable->clear(); 182 m_pAccountPropertyTable->setRowCount(0); 183 m_pAccountPropertyTable->setColumnCount(0); 184 /* Clear Cloud Profile: */ 185 m_comCloudProfile = CCloudProfile(); 186 187 /* If both provider and profile chosen: */ 188 if (!m_comCloudProvider.isNull() && !profileName().isNull()) 189 { 190 /* Acquire Cloud Profile: */ 191 m_comCloudProfile = m_comCloudProvider.GetProfileByName(profileName()); 192 /* Show error message if necessary: */ 193 if (!m_comCloudProvider.isOk()) 194 msgCenter().cannotFindCloudProfile(m_comCloudProvider, profileName()); 195 else 196 { 197 /* Acquire properties: */ 198 QVector<QString> keys; 199 QVector<QString> values; 200 values = m_comCloudProfile.GetProperties(QString(), keys); 201 /* Show error message if necessary: */ 202 if (!m_comCloudProfile.isOk()) 203 msgCenter().cannotAcquireCloudProfileParameter(m_comCloudProfile); 204 else 205 { 206 /* Configure table: */ 207 m_pAccountPropertyTable->setRowCount(keys.size()); 208 m_pAccountPropertyTable->setColumnCount(2); 209 210 /* Push acquired keys/values to data fields: */ 211 for (int i = 0; i < m_pAccountPropertyTable->rowCount(); ++i) 212 { 213 /* Create key item: */ 214 QTableWidgetItem *pItemK = new QTableWidgetItem(keys.at(i)); 215 if (pItemK) 216 { 217 /* Non-editable for sure, but non-selectable? */ 218 pItemK->setFlags(pItemK->flags() & ~Qt::ItemIsEditable); 219 pItemK->setFlags(pItemK->flags() & ~Qt::ItemIsSelectable); 220 221 /* Use non-translated description as tool-tip: */ 222 const QString strToolTip = m_comCloudProvider.GetPropertyDescription(keys.at(i)); 223 /* Show error message if necessary: */ 224 if (!m_comCloudProfile.isOk()) 225 msgCenter().cannotAcquireCloudProfileParameter(m_comCloudProfile); 226 else 227 pItemK->setData(Qt::UserRole, strToolTip); 228 229 /* Insert into table: */ 230 m_pAccountPropertyTable->setItem(i, 0, pItemK); 231 } 232 233 /* Create value item: */ 234 QTableWidgetItem *pItemV = new QTableWidgetItem(values.at(i)); 235 if (pItemV) 236 { 237 /* Non-editable for sure, but non-selectable? */ 238 pItemV->setFlags(pItemV->flags() & ~Qt::ItemIsEditable); 239 pItemV->setFlags(pItemV->flags() & ~Qt::ItemIsSelectable); 240 241 /* Use the value as tool-tip, there can be quite long values: */ 242 const QString strToolTip = values.at(i); 243 pItemV->setToolTip(strToolTip); 244 245 /* Insert into table: */ 246 m_pAccountPropertyTable->setItem(i, 1, pItemV); 247 } 248 } 249 250 /* Update table tool-tips: */ 251 updateAccountPropertyTableToolTips(); 252 253 /* Adjust the table: */ 254 adjustAccountPropertyTable(); 255 } 256 } 257 } 258 } 259 107 260 void UIWizardImportAppPage1::updatePageAppearance() 108 261 { … … 119 272 } 120 273 274 void UIWizardImportAppPage1::updateAccountPropertyTableToolTips() 275 { 276 /* Iterate through all the key items: */ 277 for (int i = 0; i < m_pAccountPropertyTable->rowCount(); ++i) 278 { 279 /* Acquire current key item: */ 280 QTableWidgetItem *pItemK = m_pAccountPropertyTable->item(i, 0); 281 if (pItemK) 282 { 283 const QString strToolTip = pItemK->data(Qt::UserRole).toString(); 284 pItemK->setToolTip(QApplication::translate("UIWizardImportAppPageBasic1", strToolTip.toUtf8().constData())); 285 } 286 } 287 } 288 289 void UIWizardImportAppPage1::adjustAccountPropertyTable() 290 { 291 /* Disable last column stretching temporary: */ 292 m_pAccountPropertyTable->horizontalHeader()->setStretchLastSection(false); 293 294 /* Resize both columns to contents: */ 295 m_pAccountPropertyTable->resizeColumnsToContents(); 296 /* Then acquire full available width: */ 297 const int iFullWidth = m_pAccountPropertyTable->viewport()->width(); 298 /* First column should not be less than it's minimum size, last gets the rest: */ 299 const int iMinimumWidth0 = qMin(m_pAccountPropertyTable->horizontalHeader()->sectionSize(0), iFullWidth / 2); 300 m_pAccountPropertyTable->horizontalHeader()->resizeSection(0, iMinimumWidth0); 301 302 /* Enable last column stretching again: */ 303 m_pAccountPropertyTable->horizontalHeader()->setStretchLastSection(true); 304 } 305 121 306 void UIWizardImportAppPage1::setSource(const QString &strSource) 122 307 { … … 143 328 const int iIndex = m_pSourceComboBox->currentIndex(); 144 329 return m_pSourceComboBox->itemData(iIndex, SourceData_ID).toUuid(); 330 } 331 332 QString UIWizardImportAppPage1::profileName() const 333 { 334 const int iIndex = m_pAccountComboBox->currentIndex(); 335 return m_pAccountComboBox->itemData(iIndex, AccountData_ProfileName).toString(); 336 } 337 338 CCloudProfile UIWizardImportAppPage1::profile() const 339 { 340 return m_comCloudProfile; 145 341 } 146 342 … … 243 439 m_pCloudContainerLayout->setContentsMargins(0, 0, 0, 0); 244 440 441 /* Create account label: */ 442 m_pAccountLabel = new QLabel; 443 if (m_pAccountLabel) 444 { 445 m_pAccountLabel->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter); 446 447 /* Add into layout: */ 448 m_pCloudContainerLayout->addWidget(m_pAccountLabel, 0, 0); 449 } 450 451 /* Create sub-layout: */ 452 QHBoxLayout *pSubLayout = new QHBoxLayout; 453 if (pSubLayout) 454 { 455 pSubLayout->setContentsMargins(0, 0, 0, 0); 456 pSubLayout->setSpacing(1); 457 458 /* Create account combo-box: */ 459 m_pAccountComboBox = new QComboBox; 460 if (m_pAccountComboBox) 461 { 462 m_pAccountLabel->setBuddy(m_pAccountComboBox); 463 464 /* Add into layout: */ 465 pSubLayout->addWidget(m_pAccountComboBox); 466 } 467 468 /* Create account tool-button: */ 469 m_pAccountToolButton = new QIToolButton; 470 if (m_pAccountToolButton) 471 { 472 m_pAccountToolButton->setIcon(UIIconPool::iconSet(":/cloud_profile_manager_16px.png", 473 ":/cloud_profile_manager_disabled_16px.png")); 474 475 /* Add into layout: */ 476 pSubLayout->addWidget(m_pAccountToolButton); 477 } 478 479 /* Add into layout: */ 480 m_pCloudContainerLayout->addLayout(pSubLayout, 0, 1); 481 } 482 483 /* Create profile property table: */ 484 m_pAccountPropertyTable = new QTableWidget; 485 if (m_pAccountPropertyTable) 486 { 487 const QFontMetrics fm(m_pAccountPropertyTable->font()); 488 const int iFontWidth = fm.width('x'); 489 const int iTotalWidth = 50 * iFontWidth; 490 const int iFontHeight = fm.height(); 491 const int iTotalHeight = 4 * iFontHeight; 492 m_pAccountPropertyTable->setMinimumSize(QSize(iTotalWidth, iTotalHeight)); 493 // m_pAccountPropertyTable->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); 494 m_pAccountPropertyTable->setAlternatingRowColors(true); 495 m_pAccountPropertyTable->horizontalHeader()->setVisible(false); 496 m_pAccountPropertyTable->verticalHeader()->setVisible(false); 497 m_pAccountPropertyTable->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); 498 499 /* Add into layout: */ 500 m_pCloudContainerLayout->addWidget(m_pAccountPropertyTable, 1, 1); 501 } 245 502 } 246 503 … … 259 516 /* Populate sources: */ 260 517 populateSources(); 518 /* Populate accounts: */ 519 populateAccounts(); 520 /* Populate account properties: */ 521 populateAccountProperties(); 261 522 262 523 /* Setup connections: */ 524 if (gpManager) 525 connect(gpManager, &UIVirtualBoxManager::sigCloudProfileManagerChange, 526 this, &UIWizardImportAppPageBasic1::sltHandleSourceChange); 263 527 connect(m_pSourceComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::activated), 264 528 this, &UIWizardImportAppPageBasic1::sltHandleSourceChange); 265 529 connect(m_pFileSelector, &UIEmptyFilePathSelector::pathChanged, 266 530 this, &UIWizardImportAppPageBasic1::completeChanged); 531 connect(m_pAccountComboBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged), 532 this, &UIWizardImportAppPageBasic1::sltHandleAccountComboChange); 533 connect(m_pAccountToolButton, &QIToolButton::clicked, 534 this, &UIWizardImportAppPageBasic1::sltHandleAccountButtonClick); 267 535 268 536 /* Register fields: */ 269 537 registerField("source", this, "source"); 270 538 registerField("isSourceCloudOne", this, "isSourceCloudOne"); 539 registerField("profile", this, "profile"); 540 } 541 542 bool UIWizardImportAppPageBasic1::event(QEvent *pEvent) 543 { 544 /* Handle known event types: */ 545 switch (pEvent->type()) 546 { 547 case QEvent::Show: 548 case QEvent::Resize: 549 { 550 /* Adjust profile property table: */ 551 adjustAccountPropertyTable(); 552 break; 553 } 554 default: 555 break; 556 } 557 558 /* Call to base-class: */ 559 return UIWizardPage::event(pEvent); 271 560 } 272 561 … … 300 589 m_pFileSelector->setFileFilters(UIWizardImportApp::tr("Open Virtualization Format (%1)").arg("*.ova *.ovf")); 301 590 591 /* Translate Account label: */ 592 m_pAccountLabel->setText(UIWizardImportApp::tr("&Account:")); 593 302 594 /* Adjust label widths: */ 303 595 QList<QWidget*> labels; 304 596 labels << m_pSourceLabel; 597 labels << m_pAccountLabel; 305 598 int iMaxWidth = 0; 306 599 foreach (QWidget *pLabel, labels) … … 314 607 /* Update tool-tips: */ 315 608 updateSourceComboToolTip(); 609 updateAccountPropertyTableToolTips(); 316 610 } 317 611 … … 324 618 bool UIWizardImportAppPageBasic1::isComplete() const 325 619 { 326 /* Make sure appliance file has allowed extension and exists: */ 327 return VBoxGlobal::hasAllowedExtension(m_pFileSelector->path().toLower(), OVFFileExts) 328 && QFile::exists(m_pFileSelector->path()); 620 bool fResult = true; 621 622 /* Check appliance settings: */ 623 if (fResult) 624 { 625 const bool fOVF = !isSourceCloudOne(); 626 const bool fCSP = !fOVF; 627 628 fResult = ( fOVF 629 && VBoxGlobal::hasAllowedExtension(m_pFileSelector->path().toLower(), OVFFileExts) 630 && QFile::exists(m_pFileSelector->path())) 631 || ( fCSP 632 && !m_comCloudProfile.isNull()); 633 } 634 635 return fResult; 329 636 } 330 637 … … 356 663 /* Refresh required settings: */ 357 664 updatePageAppearance(); 665 populateAccounts(); 666 populateAccountProperties(); 358 667 emit completeChanged(); 359 668 } 669 670 void UIWizardImportAppPageBasic1::sltHandleAccountComboChange() 671 { 672 /* Refresh required settings: */ 673 populateAccountProperties(); 674 } 675 676 void UIWizardImportAppPageBasic1::sltHandleAccountButtonClick() 677 { 678 /* Open Cloud Profile Manager: */ 679 if (gpManager) 680 gpManager->openCloudProfileManager(); 681 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageBasic1.h
r78081 r78082 34 34 /* Forward declarations: */ 35 35 class QLabel; 36 class QTableWidget; 36 37 class QStackedLayout; 37 38 class QIComboBox; 38 39 class QIRichTextLabel; 40 class QIToolButton; 39 41 class UIEmptyFilePathSelector; 40 42 … … 46 48 SourceData_ShortName = Qt::UserRole + 3, 47 49 SourceData_IsItCloudFormat = Qt::UserRole + 4 50 }; 51 52 /** Account combo data fields. */ 53 enum 54 { 55 AccountData_ProfileName = Qt::UserRole + 1 48 56 }; 49 57 … … 58 66 /** Populates sources. */ 59 67 void populateSources(); 68 /** Populates accounts. */ 69 void populateAccounts(); 70 /** Populates account properties. */ 71 void populateAccountProperties(); 60 72 61 73 /** Updates page appearance. */ … … 64 76 /** Updates source combo tool-tips. */ 65 77 void updateSourceComboToolTip(); 78 /** Updates account property table tool-tips. */ 79 void updateAccountPropertyTableToolTips(); 80 /** Adjusts account property table. */ 81 void adjustAccountPropertyTable(); 66 82 67 83 /** Defines @a strSource. */ … … 74 90 /** Returns source ID. */ 75 91 QUuid sourceId() const; 92 /** Returns profile name. */ 93 QString profileName() const; 94 /** Returns Cloud Profile object. */ 95 CCloudProfile profile() const; 76 96 77 97 /** Holds whether default source should be Import from OCI. */ … … 99 119 100 120 /** Holds the cloud container layout instance. */ 101 QGridLayout *m_pCloudContainerLayout; 121 QGridLayout *m_pCloudContainerLayout; 122 /** Holds the account label instance. */ 123 QLabel *m_pAccountLabel; 124 /** Holds the account combo-box instance. */ 125 QComboBox *m_pAccountComboBox; 126 /** Holds the account management tool-button instance. */ 127 QIToolButton *m_pAccountToolButton; 128 /** Holds the account property table instance. */ 129 QTableWidget *m_pAccountPropertyTable; 102 130 }; 103 131 … … 108 136 Q_PROPERTY(QString source READ source WRITE setSource); 109 137 Q_PROPERTY(bool isSourceCloudOne READ isSourceCloudOne); 138 Q_PROPERTY(CCloudProfile profile READ profile); 110 139 111 140 public: … … 115 144 116 145 protected: 146 147 /** Handle any Qt @a pEvent. */ 148 virtual bool event(QEvent *pEvent) /* override */; 117 149 118 150 /** Handles translation event. */ … … 133 165 void sltHandleSourceChange(); 134 166 167 /** Handles change in account combo-box. */ 168 void sltHandleAccountComboChange(); 169 170 /** Handles account tool-button click. */ 171 void sltHandleAccountButtonClick(); 172 135 173 private: 136 174
Note:
See TracChangeset
for help on using the changeset viewer.