VirtualBox

Changeset 78062 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Apr 9, 2019 1:52:22 PM (6 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9434: Import Appliance wizard: 1st basic page: Move Cloud Content Provider choice onto Main API rails, acquiring available providers there instead of hard-coding own inside GUI.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/exportappliance/UIWizardExportAppPageBasic2.cpp

    r78061 r78062  
    4747/* COM includes: */
    4848#include "CCloudClient.h"
    49 #include "CCloudProvider.h"
    5049
    5150
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppDefs.h

    r78046 r78062  
    3333Q_DECLARE_METATYPE(ImportAppliancePointer);
    3434
    35 /** Import source types. */
    36 enum ImportSourceType
    37 {
    38     ImportSourceType_Invalid,
    39     ImportSourceType_Local,
    40     ImportSourceType_Cloud
    41 };
    42 Q_DECLARE_METATYPE(ImportSourceType);
    43 
    4435#endif /* !FEQT_INCLUDED_SRC_wizards_importappliance_UIWizardImportAppDefs_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageBasic1.cpp

    r78061 r78062  
    2727#include "VBoxGlobal.h"
    2828#include "UIEmptyFilePathSelector.h"
     29#include "UIMessageCenter.h"
    2930#include "UIWizardImportApp.h"
    3031#include "UIWizardImportAppPageBasic1.h"
    3132#include "UIWizardImportAppPageBasic2.h"
    32 
    33 
    34 /*********************************************************************************************************************************
    35 *   Namespace ImportSourceTypeConverter implementation.                                                                          *
    36 *********************************************************************************************************************************/
    37 
    38 QString ImportSourceTypeConverter::toString(ImportSourceType enmType)
    39 {
    40     switch (enmType)
    41     {
    42         case ImportSourceType_Local: return QApplication::translate("UIWizardImportApp", "Local File System");
    43         case ImportSourceType_Cloud: return QApplication::translate("UIWizardImportApp", "Cloud Content Provider");
    44         default: break;
    45     }
    46     return QString();
    47 }
    4833
    4934
     
    5843    , m_pFileSelector(0)
    5944{
     45}
     46
     47void UIWizardImportAppPage1::populateSources()
     48{
     49    AssertReturnVoid(m_pSourceComboBox->count() == 0);
     50
     51    /* Compose hardcoded sources list: */
     52    QStringList sources;
     53    sources << "local";
     54    /* Add that list to combo: */
     55    foreach (const QString &strShortName, sources)
     56    {
     57        /* Compose empty item, fill it's data: */
     58        m_pSourceComboBox->addItem(QString());
     59        m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, strShortName, SourceData_ShortName);
     60    }
     61
     62    /* Initialize Cloud Provider Manager: */
     63    CVirtualBox comVBox = vboxGlobal().virtualBox();
     64    m_comCloudProviderManager = comVBox.GetCloudProviderManager();
     65    /* Show error message if necessary: */
     66    if (!comVBox.isOk())
     67        msgCenter().cannotAcquireCloudProviderManager(comVBox);
     68    else
     69    {
     70        /* Acquire existing providers: */
     71        const QVector<CCloudProvider> providers = m_comCloudProviderManager.GetProviders();
     72        /* Show error message if necessary: */
     73        if (!m_comCloudProviderManager.isOk())
     74            msgCenter().cannotAcquireCloudProviderManagerParameter(m_comCloudProviderManager);
     75        else
     76        {
     77            /* Iterate through existing providers: */
     78            foreach (const CCloudProvider &comProvider, providers)
     79            {
     80                /* Skip if we have nothing to populate (file missing?): */
     81                if (comProvider.isNull())
     82                    continue;
     83
     84                /* Compose empty item, fill it's data: */
     85                m_pSourceComboBox->addItem(QString());
     86                m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetId(),        SourceData_ID);
     87                m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetName(),      SourceData_Name);
     88                m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, comProvider.GetShortName(), SourceData_ShortName);
     89                m_pSourceComboBox->setItemData(m_pSourceComboBox->count() - 1, true,                       SourceData_IsItCloudFormat);
     90            }
     91        }
     92    }
     93
     94    /* Set default: */
     95    setSource("local");
     96}
     97
     98void UIWizardImportAppPage1::updatePageAppearance()
     99{
     100    /* Update page appearance according to chosen source: */
     101    m_pStackedLayout->setCurrentIndex((int)isSourceCloudOne());
     102}
     103
     104void UIWizardImportAppPage1::updateSourceComboToolTip()
     105{
     106    const int iCurrentIndex = m_pSourceComboBox->currentIndex();
     107    const QString strCurrentToolTip = m_pSourceComboBox->itemData(iCurrentIndex, Qt::ToolTipRole).toString();
     108    AssertMsg(!strCurrentToolTip.isEmpty(), ("Data not found!"));
     109    m_pSourceComboBox->setToolTip(strCurrentToolTip);
     110}
     111
     112void UIWizardImportAppPage1::setSource(const QString &strSource)
     113{
     114    const int iIndex = m_pSourceComboBox->findData(strSource, SourceData_ShortName);
     115    AssertMsg(iIndex != -1, ("Data not found!"));
     116    m_pSourceComboBox->setCurrentIndex(iIndex);
     117}
     118
     119QString UIWizardImportAppPage1::source() const
     120{
     121    const int iIndex = m_pSourceComboBox->currentIndex();
     122    return m_pSourceComboBox->itemData(iIndex, SourceData_ShortName).toString();
     123}
     124
     125bool UIWizardImportAppPage1::isSourceCloudOne(int iIndex /* = -1 */) const
     126{
     127    if (iIndex == -1)
     128        iIndex = m_pSourceComboBox->currentIndex();
     129    return m_pSourceComboBox->itemData(iIndex, SourceData_IsItCloudFormat).toBool();
    60130}
    61131
     
    102172                m_pSourceLabel->setBuddy(m_pSourceComboBox);
    103173                m_pSourceComboBox->hide();
    104                 m_pSourceComboBox->addItem(QString(), QVariant::fromValue(ImportSourceType_Local));
    105                 m_pSourceComboBox->addItem(QString(), QVariant::fromValue(ImportSourceType_Cloud));
    106174                connect(m_pSourceComboBox, static_cast<void(QIComboBox::*)(int)>(&QIComboBox::activated),
    107175                        this, &UIWizardImportAppPageBasic1::sltHandleSourceChange);
     
    148216
    149217                /* Add into layout: */
    150                 m_stackedLayoutIndexMap[ImportSourceType_Local] = m_pStackedLayout->addWidget(pLocalContainer);
     218                m_pStackedLayout->addWidget(pLocalContainer);
    151219            }
    152220
     
    167235
    168236                /* Add into layout: */
    169                 m_stackedLayoutIndexMap[ImportSourceType_Cloud] = m_pStackedLayout->addWidget(pCloudContainer);
     237                m_pStackedLayout->addWidget(pCloudContainer);
    170238            }
    171239
     
    178246    }
    179247
     248    /* Populate sources: */
     249    populateSources();
     250
    180251    /* Setup connections: */
    181252    connect(m_pFileSelector, &UIEmptyFilePathSelector::pathChanged, this, &UIWizardImportAppPageBasic1::completeChanged);
     253
     254    /* Register fields: */
     255    registerField("source", this, "source");
     256    registerField("isSourceCloudOne", this, "isSourceCloudOne");
    182257}
    183258
     
    194269    /* Translate source label: */
    195270    m_pSourceLabel->setText(tr("&Source:"));
     271    /* Translate hardcoded values of Source combo-box: */
     272    m_pSourceComboBox->setItemText(0, UIWizardImportApp::tr("Local File System"));
     273    m_pSourceComboBox->setItemData(0, UIWizardImportApp::tr("Import from local file system."), Qt::ToolTipRole);
    196274    /* Translate received values of Source combo-box.
    197275     * We are enumerating starting from 0 for simplicity: */
    198276    for (int i = 0; i < m_pSourceComboBox->count(); ++i)
    199         m_pSourceComboBox->setItemText(i, ImportSourceTypeConverter::toString(m_pSourceComboBox->itemData(i).value<ImportSourceType>()));
     277        if (isSourceCloudOne(i))
     278        {
     279            m_pSourceComboBox->setItemText(i, m_pSourceComboBox->itemData(i, SourceData_Name).toString());
     280            m_pSourceComboBox->setItemData(i, UIWizardImportApp::tr("Import from cloud service provider."), Qt::ToolTipRole);
     281        }
    200282
    201283    /* Translate file selector: */
     
    203285    m_pFileSelector->setFileDialogTitle(UIWizardImportApp::tr("Please choose a virtual appliance file to import"));
    204286    m_pFileSelector->setFileFilters(UIWizardImportApp::tr("Open Virtualization Format (%1)").arg("*.ova *.ovf"));
     287
     288    /* Update page appearance: */
     289    updatePageAppearance();
     290
     291    /* Update tool-tips: */
     292    updateSourceComboToolTip();
    205293}
    206294
     
    238326}
    239327
    240 void UIWizardImportAppPageBasic1::sltHandleSourceChange(int iIndex)
    241 {
    242     m_pStackedLayout->setCurrentIndex(m_stackedLayoutIndexMap.value(m_pSourceComboBox->itemData(iIndex).value<ImportSourceType>()));
    243 }
     328void UIWizardImportAppPageBasic1::sltHandleSourceChange()
     329{
     330    /* Update tool-tip: */
     331    updateSourceComboToolTip();
     332
     333    /* Refresh required settings: */
     334    updatePageAppearance();
     335    emit completeChanged();
     336}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/importappliance/UIWizardImportAppPageBasic1.h

    r78061 r78062  
    2626#include "UIWizardPage.h"
    2727
     28/* COM includes: */
     29#include "COMEnums.h"
     30#include "CCloudProfile.h"
     31#include "CCloudProvider.h"
     32#include "CCloudProviderManager.h"
     33
    2834/* Forward declarations: */
    2935class QLabel;
     
    3339class UIEmptyFilePathSelector;
    3440
    35 /** Source type converter namespace. */
    36 namespace ImportSourceTypeConverter
     41/** Source combo data fields. */
     42enum
    3743{
    38     /** Converts QString <= ImportSourceType. */
    39     QString toString(ImportSourceType enmType);
    40 }
     44    SourceData_ID              = Qt::UserRole + 1,
     45    SourceData_Name            = Qt::UserRole + 2,
     46    SourceData_ShortName       = Qt::UserRole + 3,
     47    SourceData_IsItCloudFormat = Qt::UserRole + 4
     48};
    4149
    4250/** UIWizardPageBase extension for 1st page of the Import Appliance wizard. */
     
    4856    UIWizardImportAppPage1();
    4957
     58    /** Populates sources. */
     59    void populateSources();
     60
     61    /** Updates page appearance. */
     62    virtual void updatePageAppearance();
     63
     64    /** Updates source combo tool-tips. */
     65    void updateSourceComboToolTip();
     66
     67    /** Defines @a strSource. */
     68    void setSource(const QString &strSource);
     69    /** Returns source. */
     70    QString source() const;
     71    /** Returns whether source under certain @a iIndex is cloud one. */
     72    bool isSourceCloudOne(int iIndex = -1) const;
     73
     74    /** Holds whether default source should be Import from OCI. */
     75    bool  m_fImportFromOCIByDefault;
     76
     77    /** Holds the Cloud Provider Manager reference. */
     78    CCloudProviderManager  m_comCloudProviderManager;
     79    /** Holds the Cloud Provider object reference. */
     80    CCloudProvider         m_comCloudProvider;
     81    /** Holds the Cloud Profile object reference. */
     82    CCloudProfile          m_comCloudProfile;
     83
    5084    /** Holds the source type label instance. */
    5185    QLabel     *m_pSourceLabel;
     
    5488
    5589    /** Holds the stacked layout instance. */
    56     QStackedLayout              *m_pStackedLayout;
    57     /** Holds the stacked layout widget indexes map. */
    58     QMap<ImportSourceType, int>  m_stackedLayoutIndexMap;
     90    QStackedLayout *m_pStackedLayout;
    5991
    6092    /** Holds the file selector instance. */
     
    6698{
    6799    Q_OBJECT;
     100    Q_PROPERTY(QString source READ source WRITE setSource);
     101    Q_PROPERTY(bool isSourceCloudOne READ isSourceCloudOne);
    68102
    69103public:
     
    88122private slots:
    89123
    90     /** Handles change of import source to one with specified @a iIndex. */
    91     void sltHandleSourceChange(int iIndex);
     124    /** Handles import source change. */
     125    void sltHandleSourceChange();
    92126
    93127private:
Note: See TracChangeset for help on using the changeset viewer.

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