VirtualBox

Changeset 78082 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Apr 10, 2019 11:56:38 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
129938
Message:

FE/Qt: bugref:9434: Import Appliance wizard: 1st basic page: Integrate hidden for now cloud account property controls.

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  
    1818/* Qt includes: */
    1919#include <QFileInfo>
     20#include <QHeaderView>
    2021#include <QLabel>
    2122#include <QStackedLayout>
     23#include <QTableWidget>
    2224#include <QVBoxLayout>
    2325
     
    2527#include "QIComboBox.h"
    2628#include "QIRichTextLabel.h"
     29#include "QIToolButton.h"
    2730#include "VBoxGlobal.h"
    2831#include "UIEmptyFilePathSelector.h"
     32#include "UIIconPool.h"
    2933#include "UIMessageCenter.h"
     34#include "UIVirtualBoxManager.h"
    3035#include "UIWizardImportApp.h"
    3136#include "UIWizardImportAppPageBasic1.h"
     
    4550    , m_pFileSelector(0)
    4651    , m_pCloudContainerLayout(0)
     52    , m_pAccountLabel(0)
     53    , m_pAccountComboBox(0)
     54    , m_pAccountToolButton(0)
     55    , m_pAccountPropertyTable(0)
    4756{
    4857}
     
    105114}
    106115
     116void 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
     178void 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
    107260void UIWizardImportAppPage1::updatePageAppearance()
    108261{
     
    119272}
    120273
     274void 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
     289void 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
    121306void UIWizardImportAppPage1::setSource(const QString &strSource)
    122307{
     
    143328    const int iIndex = m_pSourceComboBox->currentIndex();
    144329    return m_pSourceComboBox->itemData(iIndex, SourceData_ID).toUuid();
     330}
     331
     332QString UIWizardImportAppPage1::profileName() const
     333{
     334    const int iIndex = m_pAccountComboBox->currentIndex();
     335    return m_pAccountComboBox->itemData(iIndex, AccountData_ProfileName).toString();
     336}
     337
     338CCloudProfile UIWizardImportAppPage1::profile() const
     339{
     340    return m_comCloudProfile;
    145341}
    146342
     
    243439                    m_pCloudContainerLayout->setContentsMargins(0, 0, 0, 0);
    244440
     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                    }
    245502                }
    246503
     
    259516    /* Populate sources: */
    260517    populateSources();
     518    /* Populate accounts: */
     519    populateAccounts();
     520    /* Populate account properties: */
     521    populateAccountProperties();
    261522
    262523    /* Setup connections: */
     524    if (gpManager)
     525        connect(gpManager, &UIVirtualBoxManager::sigCloudProfileManagerChange,
     526                this, &UIWizardImportAppPageBasic1::sltHandleSourceChange);
    263527    connect(m_pSourceComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::activated),
    264528            this, &UIWizardImportAppPageBasic1::sltHandleSourceChange);
    265529    connect(m_pFileSelector, &UIEmptyFilePathSelector::pathChanged,
    266530            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);
    267535
    268536    /* Register fields: */
    269537    registerField("source", this, "source");
    270538    registerField("isSourceCloudOne", this, "isSourceCloudOne");
     539    registerField("profile", this, "profile");
     540}
     541
     542bool 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);
    271560}
    272561
     
    300589    m_pFileSelector->setFileFilters(UIWizardImportApp::tr("Open Virtualization Format (%1)").arg("*.ova *.ovf"));
    301590
     591    /* Translate Account label: */
     592    m_pAccountLabel->setText(UIWizardImportApp::tr("&Account:"));
     593
    302594    /* Adjust label widths: */
    303595    QList<QWidget*> labels;
    304596    labels << m_pSourceLabel;
     597    labels << m_pAccountLabel;
    305598    int iMaxWidth = 0;
    306599    foreach (QWidget *pLabel, labels)
     
    314607    /* Update tool-tips: */
    315608    updateSourceComboToolTip();
     609    updateAccountPropertyTableToolTips();
    316610}
    317611
     
    324618bool UIWizardImportAppPageBasic1::isComplete() const
    325619{
    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;
    329636}
    330637
     
    356663    /* Refresh required settings: */
    357664    updatePageAppearance();
     665    populateAccounts();
     666    populateAccountProperties();
    358667    emit completeChanged();
    359668}
     669
     670void UIWizardImportAppPageBasic1::sltHandleAccountComboChange()
     671{
     672    /* Refresh required settings: */
     673    populateAccountProperties();
     674}
     675
     676void 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  
    3434/* Forward declarations: */
    3535class QLabel;
     36class QTableWidget;
    3637class QStackedLayout;
    3738class QIComboBox;
    3839class QIRichTextLabel;
     40class QIToolButton;
    3941class UIEmptyFilePathSelector;
    4042
     
    4648    SourceData_ShortName       = Qt::UserRole + 3,
    4749    SourceData_IsItCloudFormat = Qt::UserRole + 4
     50};
     51
     52/** Account combo data fields. */
     53enum
     54{
     55    AccountData_ProfileName = Qt::UserRole + 1
    4856};
    4957
     
    5866    /** Populates sources. */
    5967    void populateSources();
     68    /** Populates accounts. */
     69    void populateAccounts();
     70    /** Populates account properties. */
     71    void populateAccountProperties();
    6072
    6173    /** Updates page appearance. */
     
    6476    /** Updates source combo tool-tips. */
    6577    void updateSourceComboToolTip();
     78    /** Updates account property table tool-tips. */
     79    void updateAccountPropertyTableToolTips();
     80    /** Adjusts account property table. */
     81    void adjustAccountPropertyTable();
    6682
    6783    /** Defines @a strSource. */
     
    7490    /** Returns source ID. */
    7591    QUuid sourceId() const;
     92    /** Returns profile name. */
     93    QString profileName() const;
     94    /** Returns Cloud Profile object. */
     95    CCloudProfile profile() const;
    7696
    7797    /** Holds whether default source should be Import from OCI. */
     
    99119
    100120    /** 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;
    102130};
    103131
     
    108136    Q_PROPERTY(QString source READ source WRITE setSource);
    109137    Q_PROPERTY(bool isSourceCloudOne READ isSourceCloudOne);
     138    Q_PROPERTY(CCloudProfile profile READ profile);
    110139
    111140public:
     
    115144
    116145protected:
     146
     147    /** Handle any Qt @a pEvent. */
     148    virtual bool event(QEvent *pEvent) /* override */;
    117149
    118150    /** Handles translation event. */
     
    133165    void sltHandleSourceChange();
    134166
     167    /** Handles change in account combo-box. */
     168    void sltHandleAccountComboChange();
     169
     170    /** Handles account tool-button click. */
     171    void sltHandleAccountButtonClick();
     172
    135173private:
    136174
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette