VirtualBox

Changeset 100861 in vbox for trunk/src


Ignore:
Timestamp:
Aug 11, 2023 3:38:01 PM (18 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10500: Initial implementation for cloud VM clone functionality; This isn't working for now since ICloudMachine has only id, but not ocid property accessible.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICloudNetworkingStuff.cpp

    r98103 r100861  
    603603    return pParent->handleNow(pNotification);
    604604}
     605
     606void UICloudNetworkingStuff::createCloudMachineClone(const QString &strProviderShortName,
     607                                                     const QString &strProfileName,
     608                                                     const CCloudMachine &comCloudMachine,
     609                                                     const QString &strCloneName,
     610                                                     UINotificationCenter *pParent)
     611{
     612    /* Create cloud client: */
     613    CCloudClient comCloudClient = cloudClientByName(strProviderShortName,
     614                                                    strProfileName,
     615                                                    pParent);
     616    if (comCloudClient.isNotNull())
     617    {
     618        /* Clone specified cloud machine asynchronously: */
     619        UINotificationProgressCloudMachineClone *pNotification =
     620            new UINotificationProgressCloudMachineClone(comCloudClient, comCloudMachine, strCloneName);
     621        pParent->append(pNotification);
     622    }
     623}
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICloudNetworkingStuff.h

    r98103 r100861  
    184184                                                            const CForm &comForm,
    185185                                                            UINotificationCenter *pParent);
     186
     187    /** Creates cloud machine clone.
     188      * @param  strProviderShortName  Brings short provider name.
     189      * @param  strProfileName        Brings profile name.
     190      * @param  comCloudMachine       Brings cloud machine instance of which being cloned.
     191      * @param  strCloneName          Brings clone name.
     192      * @param  pParent               Brings notification-center reference. */
     193    SHARED_LIBRARY_STUFF void createCloudMachineClone(const QString &strProviderShortName,
     194                                                      const QString &strProfileName,
     195                                                      const CCloudMachine &comCloudMachine,
     196                                                      const QString &strCloneName,
     197                                                      UINotificationCenter *pParent);
    186198}
    187199
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r100654 r100861  
    5050#include "QIDialogButtonBox.h"
    5151#include "QIFileDialog.h"
     52#include "QILineEdit.h"
    5253#include "QIRichTextLabel.h"
    5354#include "UIActionPoolManager.h"
     
    169170};
    170171
     172/** QDialog extension used to ask for a cloud machine clone name. */
     173class UIAcquireCloudMachineCloneNameDialog : public QIWithRetranslateUI<QDialog>
     174{
     175    Q_OBJECT;
     176
     177public:
     178
     179    /** Constructs dialog passing @a pParent to the base-class.
     180      * @param  strName  Brings the clone name by default. */
     181    UIAcquireCloudMachineCloneNameDialog(QWidget *pParent, const QString &strName);
     182
     183    /** Returns value. */
     184    QString value() const;
     185
     186protected:
     187
     188    /** Handles translation event. */
     189    virtual void retranslateUi() RT_OVERRIDE;
     190
     191private slots:
     192
     193    /** Performs revalidation. */
     194    void sltRevalidate();
     195
     196private:
     197
     198    /** Prepares all. */
     199    void prepare();
     200    /** Prepares widgets. */
     201    void prepareWidgets();
     202
     203    /** Holds the clone name by default. */
     204    QString  m_strName;
     205
     206    /** Holds the text-editor instance. */
     207    QILineEdit        *m_pEditor;
     208    /** Holds the button-box instance. */
     209    QIDialogButtonBox *m_pButtonBox;
     210};
     211
    171212
    172213/*********************************************************************************************************************************
     
    433474    m_pTextEditor->setPlainText(file.readAll());
    434475    return true;
     476}
     477
     478
     479/*********************************************************************************************************************************
     480*   Class UIAcquireCloudMachineCloneNameDialog implementation.                                                                   *
     481*********************************************************************************************************************************/
     482
     483UIAcquireCloudMachineCloneNameDialog::UIAcquireCloudMachineCloneNameDialog(QWidget *pParent, const QString &strName)
     484    : QIWithRetranslateUI<QDialog>(pParent)
     485    , m_strName(strName)
     486    , m_pEditor(0)
     487    , m_pButtonBox(0)
     488{
     489    prepare();
     490    sltRevalidate();
     491}
     492
     493QString UIAcquireCloudMachineCloneNameDialog::value() const
     494{
     495    return m_pEditor ? m_pEditor->text() : QString();
     496}
     497
     498void UIAcquireCloudMachineCloneNameDialog::prepare()
     499{
     500    /* Prepare widgets: */
     501    prepareWidgets();
     502    /* Apply language settings: */
     503    retranslateUi();
     504
     505    /* Resize to suitable size: */
     506    const int iMinimumHeightHint = minimumSizeHint().height();
     507    resize(iMinimumHeightHint * 1.618, iMinimumHeightHint);
     508}
     509
     510void UIAcquireCloudMachineCloneNameDialog::prepareWidgets()
     511{
     512    /* Prepare layout: */
     513    QVBoxLayout *pLayout = new QVBoxLayout(this);
     514    if (pLayout)
     515    {
     516        /* Prepare editor: */
     517        m_pEditor = new QILineEdit(this);
     518        if (m_pEditor)
     519        {
     520            m_pEditor->setText(m_strName);
     521            m_pEditor->setMinimumWidthByText(QString().fill('0', 20));
     522            connect(m_pEditor, &QILineEdit::textChanged, this, &UIAcquireCloudMachineCloneNameDialog::sltRevalidate);
     523            pLayout->addWidget(m_pEditor);
     524        }
     525
     526        /* Intermediate stretch: */
     527        pLayout->addStretch();
     528
     529        /* Prepare button-box: */
     530        m_pButtonBox = new QIDialogButtonBox(this);
     531        if (m_pButtonBox)
     532        {
     533            m_pButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
     534            connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIAcquireCloudMachineCloneNameDialog::accept);
     535            connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIAcquireCloudMachineCloneNameDialog::reject);
     536            pLayout->addWidget(m_pButtonBox);
     537        }
     538    }
     539}
     540
     541void UIAcquireCloudMachineCloneNameDialog::retranslateUi()
     542{
     543    setWindowTitle(tr("Clone name"));
     544    m_pEditor->setPlaceholderText(tr("Enter clone name"));
     545}
     546
     547void UIAcquireCloudMachineCloneNameDialog::sltRevalidate()
     548{
     549    m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_pEditor->text().isEmpty());
    435550}
    436551
     
    12371352void UIVirtualBoxManager::sltOpenCloneMachineWizard()
    12381353{
    1239     /* Configure wizard variables: */
    1240     m_fSnapshotCloneByDefault = false;
    1241     QAction *pAction = qobject_cast<QAction*>(sender());
    1242     if (   pAction
    1243         && pAction == actionPool()->action(UIActionIndexMN_M_Snapshot_S_Clone))
    1244         m_fSnapshotCloneByDefault = true;
    1245 
    1246     /* Open Clone VM Wizard: */
    1247     sltOpenWizard(WizardType_CloneVM);
     1354    /* Get current items: */
     1355    QList<UIVirtualMachineItem*> items = currentItems();
     1356
     1357    /* We are opening Clone VM wizard for local VMs only: */
     1358    if (isItemsLocal(items))
     1359    {
     1360        /* Configure wizard variables: */
     1361        m_fSnapshotCloneByDefault = false;
     1362        QAction *pAction = qobject_cast<QAction*>(sender());
     1363        if (   pAction
     1364            && pAction == actionPool()->action(UIActionIndexMN_M_Snapshot_S_Clone))
     1365            m_fSnapshotCloneByDefault = true;
     1366
     1367        /* Open Clone VM Wizard: */
     1368        sltOpenWizard(WizardType_CloneVM);
     1369    }
     1370    /* For cloud VMs we have no such wizard for now: */
     1371    else if (isItemsCloud(items))
     1372    {
     1373        /* Acquire item, propose clone name: */
     1374        UIVirtualMachineItem *pItem = items.first();
     1375        const QString strName = QString("%1_clone").arg(pItem->name());
     1376
     1377        /* Create Acquire Clone VM name dialog: */
     1378        QPointer<UIAcquireCloudMachineCloneNameDialog> pDialog = new UIAcquireCloudMachineCloneNameDialog(this, strName);
     1379        if (pDialog->exec() == QDialog::Accepted)
     1380        {
     1381            /* Parse current full group name: */
     1382            const QString strFullGroupName = m_pWidget->fullGroupName();
     1383            const QString strProviderShortName = strFullGroupName.section('/', 1, 1);
     1384            const QString strProfileName = strFullGroupName.section('/', 2, 2);
     1385
     1386            /* Acquire cloud machine: */
     1387            const CCloudMachine comMachine = pItem->toCloud()->machine();
     1388
     1389            /* Clone VM: */
     1390            createCloudMachineClone(strProviderShortName, strProfileName,
     1391                                    comMachine, pDialog->value(),
     1392                                    gpNotificationCenter);
     1393       }
     1394       delete pDialog;
     1395    }
    12481396}
    12491397
     
    29983146        pMenu->addSeparator();
    29993147        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Settings));
     3148        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Clone));
    30003149        pMenu->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Remove));
    30013150        pMenu->addSeparator();
     
    35443693            return !isGroupSavingInProgress() &&
    35453694                   items.size() == 1 &&
    3546                    pItem->toLocal() &&
    35473695                   pItem->isItemEditable();
    35483696        }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r100654 r100861  
    15641564    {
    15651565        pMenuMachine->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Settings));
     1566        pMenuMachine->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Clone));
    15661567        pMenuMachine->addAction(actionPool()->action(UIActionIndexMN_M_Machine_S_Remove));
    15671568        pMenuMachine->addSeparator();
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.cpp

    r100654 r100861  
    31843184    if (error().isEmpty())
    31853185        emit sigCloudMachineRemoved(m_strProviderShortName, m_strProfileName, m_strName);
     3186}
     3187
     3188
     3189/*********************************************************************************************************************************
     3190*   Class UINotificationProgressCloudMachineClone implementation.                                                                *
     3191*********************************************************************************************************************************/
     3192
     3193UINotificationProgressCloudMachineClone::UINotificationProgressCloudMachineClone(const CCloudClient &comClient,
     3194                                                                                 const CCloudMachine &comMachine,
     3195                                                                                 const QString &strCloneName)
     3196    : m_comClient(comClient)
     3197    , m_comMachine(comMachine)
     3198    , m_strCloneName(strCloneName)
     3199{
     3200}
     3201
     3202QString UINotificationProgressCloudMachineClone::name() const
     3203{
     3204    return UINotificationProgress::tr("Cloning cloud VM ...");
     3205}
     3206
     3207QString UINotificationProgressCloudMachineClone::details() const
     3208{
     3209    return UINotificationProgress::tr("<b>VM Name:</b> %1").arg(m_strName);
     3210}
     3211
     3212CProgress UINotificationProgressCloudMachineClone::createProgress(COMResult &comResult)
     3213{
     3214    // This is wrong, we need to acquire ocid, we have no one for now ..
     3215    m_uId = m_comMachine.GetId();
     3216    if (!m_comMachine.isOk())
     3217    {
     3218        /* Store COM result: */
     3219        comResult = m_comMachine;
     3220        /* Return progress-wrapper: */
     3221        return CProgress();
     3222    }
     3223    /* Acquire cloud VM name: */
     3224    m_strName = m_comMachine.GetName();
     3225    if (!m_comMachine.isOk())
     3226    {
     3227        /* Store COM result: */
     3228        comResult = m_comMachine;
     3229        /* Return progress-wrapper: */
     3230        return CProgress();
     3231    }
     3232
     3233    /* Initialize progress-wrapper: */
     3234    CCloudMachine comCloneMachine;
     3235    // This is wrong, we need to pass ocid, we have no one for now ..
     3236    const QString strId = m_uId.toString();
     3237    CProgress comProgress = m_comClient.CloneInstance(strId, m_strCloneName, comCloneMachine);
     3238    /* Store COM result: */
     3239    comResult = m_comMachine;
     3240    /* Return progress-wrapper: */
     3241    return comProgress;
    31863242}
    31873243
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h

    r100654 r100861  
    18221822};
    18231823
     1824/** UINotificationProgress extension for cloud machine clone functionality. */
     1825class SHARED_LIBRARY_STUFF UINotificationProgressCloudMachineClone : public UINotificationProgress
     1826{
     1827    Q_OBJECT;
     1828
     1829public:
     1830
     1831    /** Constructs cloud machine clone notification-progress.
     1832      * @param  comClient     Brings the cloud client to clone cloud machine.
     1833      * @param  comMachine    Brings the cloud machine to be cloned.
     1834      * @param  strCloneName  Brings the clone name. */
     1835    UINotificationProgressCloudMachineClone(const CCloudClient &comClient,
     1836                                            const CCloudMachine &comMachine,
     1837                                            const QString &strCloneName);
     1838
     1839protected:
     1840
     1841    /** Returns object name. */
     1842    virtual QString name() const /* override final */;
     1843    /** Returns object details. */
     1844    virtual QString details() const /* override final */;
     1845    /** Creates and returns started progress-wrapper. */
     1846    virtual CProgress createProgress(COMResult &comResult) /* override final */;
     1847
     1848private:
     1849
     1850    /** Holds the client cloning machine. */
     1851    CCloudClient   m_comClient;
     1852    /** Holds the machine being reset. */
     1853    CCloudMachine  m_comMachine;
     1854    /** Holds the clone name. */
     1855    QString        m_strCloneName;
     1856    // This is wrong, we need to store ocid, we have no one for now ..
     1857    QUuid          m_uId;
     1858    /** Holds the machine name. */
     1859    QString        m_strName;
     1860};
     1861
    18241862/** UINotificationProgress extension for cloud machine reset functionality. */
    18251863class SHARED_LIBRARY_STUFF UINotificationProgressCloudMachineReset : public UINotificationProgress
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