VirtualBox

Changeset 74921 in vbox


Ignore:
Timestamp:
Oct 18, 2018 2:15:19 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125925
Message:

FE/Qt: bugref:9230: A possibility to add/remove profiles.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/cloud/UICloudProfileManager.cpp

    r74920 r74921  
    2222/* Qt includes: */
    2323# include <QHeaderView>
     24# include <QInputDialog>
    2425# include <QPushButton>
    2526# include <QVBoxLayout>
     
    260261void UICloudProfileManagerWidget::sltAddCloudProfile()
    261262{
    262     /// @todo create cloud profile!
     263    /* Get provider item: */
     264    UIItemCloudProvider *pProviderItem = static_cast<UIItemCloudProvider*>(m_pTreeWidget->currentItem());
     265    AssertMsgReturnVoid(pProviderItem, ("Current item must not be null!\n"));
     266
     267    /* Acquire profile name first of all: */
     268    QString strProfileName;
     269    QPointer<QInputDialog> pDialog = new QInputDialog(this);
     270    pDialog->setInputMode(QInputDialog::TextInput);
     271    pDialog->setWindowIcon(UIIconPool::iconSet(":/cloud_profile_add_16px.png"));
     272    pDialog->setWindowTitle(tr("Add Profile"));
     273    pDialog->setLabelText(tr("Name:"));
     274    bool fCancelled = false;
     275    if (pDialog->exec() == QDialog::Accepted)
     276        strProfileName = pDialog->textValue();
     277    else
     278        fCancelled = true;
     279    delete pDialog;
     280    if (fCancelled)
     281        return;
     282
     283    /* Get VirtualBox for further activities: */
     284    const CVirtualBox comVBox = vboxGlobal().virtualBox();
     285
     286    /* Get CloudProviderManager for further activities: */
     287    CCloudProviderManager comCloudProviderManager = comVBox.GetCloudProviderManager();
     288    /* Show error message if necessary: */
     289    if (!comVBox.isOk())
     290        msgCenter().cannotAcquireCloudProviderManager(comVBox, this);
     291    else
     292    {
     293        /* Acquire provider ID: */
     294        const QUuid uId = pProviderItem->data(Column_Name, Data_ProviderID).toUuid();
     295
     296        /* Look for corresponding provider: */
     297        CCloudProvider comCloudProvider = comCloudProviderManager.GetProviderById(uId);
     298        /* Show error message if necessary: */
     299        if (!comCloudProviderManager.isOk())
     300            msgCenter().cannotFindCloudProvider(comCloudProviderManager, uId, this);
     301        else
     302        {
     303            /* Create new profile: */
     304            QVector<QString> keys;
     305            QVector<QString> values;
     306            comCloudProvider.CreateProfile(strProfileName, keys, values);
     307
     308            /* Show error message if necessary: */
     309            if (!comCloudProvider.isOk())
     310                msgCenter().cannotCreateCloudProfle(comCloudProvider, this);
     311            else
     312            {
     313                /* Look for corresponding profile: */
     314                CCloudProfile comCloudProfile = comCloudProvider.GetProfileByName(strProfileName);
     315                /* Show error message if necessary: */
     316                if (!comCloudProvider.isOk())
     317                    msgCenter().cannotFindCloudProfile(comCloudProvider, strProfileName, this);
     318                else
     319                {
     320                    /* Add profile to the tree: */
     321                    UIDataCloudProfile data;
     322                    loadCloudProfile(comCloudProfile, data);
     323                    createItemForCloudProfile(pProviderItem, data, true);
     324                }
     325            }
     326        }
     327    }
    263328}
    264329
    265330void UICloudProfileManagerWidget::sltRemoveCloudProfile()
    266331{
    267     /// @todo remove cloud profile!
     332    /* Get profile item: */
     333    UIItemCloudProfile *pProfileItem = static_cast<UIItemCloudProfile*>(m_pTreeWidget->currentItem());
     334    AssertMsgReturnVoid(pProfileItem, ("Current item must not be null!\n"));
     335
     336    /* Get profile name: */
     337    const QString strProfileName(pProfileItem->name());
     338
     339    /* Confirm cloud profile removal: */
     340    if (!msgCenter().confirmCloudProfileRemoval(strProfileName, this))
     341        return;
     342
     343    /* Get VirtualBox for further activities: */
     344    const CVirtualBox comVBox = vboxGlobal().virtualBox();
     345
     346    /* Get CloudProviderManager for further activities: */
     347    CCloudProviderManager comCloudProviderManager = comVBox.GetCloudProviderManager();
     348    /* Show error message if necessary: */
     349    if (!comVBox.isOk())
     350        msgCenter().cannotAcquireCloudProviderManager(comVBox, this);
     351    else
     352    {
     353        /* Get provider item: */
     354        UIItemCloudProvider *pProviderItem = static_cast<UIItemCloudProvider*>(pProfileItem->parentItem());
     355        /* Acquire provider ID: */
     356        const QUuid uId = pProviderItem->data(Column_Name, Data_ProviderID).toUuid();
     357
     358        /* Look for corresponding provider: */
     359        CCloudProvider comCloudProvider = comCloudProviderManager.GetProviderById(uId);
     360        /* Show error message if necessary: */
     361        if (!comCloudProviderManager.isOk())
     362            msgCenter().cannotFindCloudProvider(comCloudProviderManager, uId, this);
     363        else
     364        {
     365            /* Look for corresponding profile: */
     366            CCloudProfile comCloudProfile = comCloudProvider.GetProfileByName(strProfileName);
     367            /* Show error message if necessary: */
     368            if (!comCloudProvider.isOk())
     369                msgCenter().cannotFindCloudProfile(comCloudProvider, strProfileName, this);
     370            else
     371            {
     372                /* Remove current profile: */
     373                comCloudProfile.Remove();
     374                /// @todo how do we check that?
     375
     376                /* Remove interface from the tree: */
     377                delete pProfileItem;
     378            }
     379        }
     380    }
    268381}
    269382
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r74898 r74921  
    16411641}
    16421642
     1643void UIMessageCenter::cannotCreateCloudProfle(const CCloudProvider &comProvider, QWidget *pParent /* = 0 */) const
     1644{
     1645    error(pParent, MessageType_Error,
     1646          tr("Failed to create cloud profile."),
     1647          UIErrorString::formatErrorInfo(comProvider));
     1648}
     1649
    16431650void UIMessageCenter::cannotAcquireCloudProfileParameter(const CCloudProfile &comProfile, QWidget *pParent /* = 0 */) const
    16441651{
     
    16531660          tr("Failed to assign cloud profile parameter."),
    16541661          UIErrorString::formatErrorInfo(comProfile));
     1662}
     1663
     1664bool UIMessageCenter::confirmCloudProfileRemoval(const QString &strName, QWidget *pParent /* = 0 */) const
     1665{
     1666    return questionBinary(pParent, MessageType_Question,
     1667                          tr("<p>Do you want to remove the cloud profile <nobr><b>%1</b>?</nobr></p>")
     1668                             .arg(strName),
     1669                          0 /* auto-confirm id */,
     1670                          tr("Remove") /* ok button text */,
     1671                          QString() /* cancel button text */,
     1672                          false /* ok button by default? */);
    16551673}
    16561674
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r74898 r74921  
    365365    void cannotAcquireCloudProviderParameter(const CCloudProvider &comProvider, QWidget *pParent = 0) const;
    366366    void cannotFindCloudProfile(const CCloudProvider &comProvider, const QString &strName, QWidget *pParent = 0) const;
     367    void cannotCreateCloudProfle(const CCloudProvider &comProvider, QWidget *pParent = 0) const;
    367368    void cannotAcquireCloudProfileParameter(const CCloudProfile &comProfile, QWidget *pParent = 0) const;
    368369    void cannotAssignCloudProfileParameter(const CCloudProfile &comProfile, QWidget *pParent = 0) const;
     370    bool confirmCloudProfileRemoval(const QString &strName, QWidget *pParent = 0) const;
    369371
    370372    /* API: Wizards warnings: */
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