VirtualBox

Changeset 83008 in vbox


Ignore:
Timestamp:
Feb 6, 2020 2:59:10 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Chooser pane: Advancing r136014 to asynchronously acquire cloud instance list and append received items to corresponding profile groups; For that separate thread task sub-class was introduced.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r82998 r83008  
    631631        src/manager/chooser/UIChooserNodeMachine.h \
    632632        src/manager/chooser/UIChooserSearchWidget.h \
     633        src/manager/chooser/UITaskCloudAcquireInstances.h \
    633634        src/manager/details/UIDetails.h \
    634635        src/manager/details/UIDetailsContextMenu.h \
     
    10761077        src/manager/chooser/UIChooserNodeMachine.cpp \
    10771078        src/manager/chooser/UIChooserSearchWidget.cpp \
     1079        src/manager/chooser/UITaskCloudAcquireInstances.cpp \
    10781080        src/manager/details/UIDetails.cpp \
    10791081        src/manager/details/UIDetailsContextMenu.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UITask.h

    r82998 r83008  
    4444    enum Type
    4545    {
    46         Type_MediumEnumeration = 1,
    47         Type_DetailsPopulation = 2,
     46        Type_MediumEnumeration     = 1,
     47        Type_DetailsPopulation     = 2,
     48        Type_CloudAcquireInstances = 3,
    4849    };
    4950
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.cpp

    r82999 r83008  
    2828#include "UIVirtualBoxEventHandler.h"
    2929#include "UIVirtualMachineItem.h"
     30#ifdef VBOX_GUI_WITH_CLOUD_VMS
     31# include "UITaskCloudAcquireInstances.h"
     32# include "UIThreadPool.h"
     33#endif
    3034
    3135/* COM includes: */
     
    259263    saveGroupOrders();
    260264}
     265
     266#ifdef VBOX_GUI_WITH_CLOUD_VMS
     267void UIChooserAbstractModel::sltHandleCloudAcquireInstancesTaskComplete(UITask *pTask)
     268{
     269    /* Skip unrelated tasks: */
     270    if (!pTask || pTask->type() != UITask::Type_CloudAcquireInstances)
     271        return;
     272
     273    /* Cast task to corresponding sub-class: */
     274    UITaskCloudAcquireInstances *pAcquiringTask = static_cast<UITaskCloudAcquireInstances*>(pTask);
     275
     276    /* Add real cloud VM items: */
     277    int iPosition = 1; /* we've got item with index 0 already, the "Empty" one .. */
     278    foreach (const QString &strInstanceName, pAcquiringTask->instanceNames())
     279    {
     280        new UIChooserNodeMachine(pAcquiringTask->parentNode(),
     281                                 false /* favorite */,
     282                                 iPosition++ /* position */,
     283                                 strInstanceName);
     284    }
     285}
     286#endif /* VBOX_GUI_WITH_CLOUD_VMS */
    261287
    262288void UIChooserAbstractModel::sltGroupDefinitionsSaveComplete()
     
    374400                            new UIChooserNodeGroup(m_pInvisibleRootNode,
    375401                                                   false /* favorite */,
    376                                                    getDesiredNodePosition(m_pInvisibleRootNode, UIChooserItemType_Group, strProviderName),
     402                                                   getDesiredNodePosition(m_pInvisibleRootNode,
     403                                                                          UIChooserItemType_Group,
     404                                                                          strProviderName),
    377405                                                   strProviderName,
    378406                                                   true /* opened */);
     
    394422                                /* Create Cloud Client: */
    395423                                CCloudClient comCloudClient = comCloudProfile.CreateCloudClient();
    396                                 Q_UNUSED(comCloudClient);
    397424                                /* Show error message if necessary: */
    398425                                if (!comCloudProfile.isOk())
     
    404431                                        new UIChooserNodeGroup(pProviderNode,
    405432                                                               false /* favorite */,
    406                                                                getDesiredNodePosition(pProviderNode, UIChooserItemType_Group, strProfileName),
     433                                                               getDesiredNodePosition(pProviderNode,
     434                                                                                      UIChooserItemType_Group,
     435                                                                                      strProfileName),
    407436                                                               strProfileName,
    408437                                                               true /* opened */);
     
    411440                                                             false /* favorite */,
    412441                                                             0 /* position */);
     442
     443                                    /* Create cloud acquire isntances task: */
     444                                    UITaskCloudAcquireInstances *pTask = new UITaskCloudAcquireInstances(comCloudClient,
     445                                                                                                         pProfileNode);
     446                                    if (pTask)
     447                                    {
     448                                        connect(pTask, &UITask::sigComplete,
     449                                                this, &UIChooserAbstractModel::sltHandleCloudAcquireInstancesTaskComplete);
     450                                        uiCommon().threadPool()->enqueueTask(pTask);
     451                                    }
    413452                                }
    414453                            }
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserAbstractModel.h

    r82968 r83008  
    3636class UIChooserNode;
    3737class CMachine;
     38#ifdef VBOX_GUI_WITH_CLOUD_VMS
     39class UITask;
     40#endif
    3841
    3942
     
    130133        virtual void sltReloadMachine(const QUuid &uMachineId);
    131134    /** @} */
     135
     136#ifdef VBOX_GUI_WITH_CLOUD_VMS
     137    /** @name Cloud stuff.
     138      * @{ */
     139        /** Handles acquire cloud instances task complete signal. */
     140        virtual void sltHandleCloudAcquireInstancesTaskComplete(UITask *pTask);
     141    /** @} */
     142#endif /* VBOX_GUI_WITH_CLOUD_VMS */
    132143
    133144private slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.cpp

    r82968 r83008  
    705705    emit sigSelectionChanged();
    706706}
     707
     708#ifdef VBOX_GUI_WITH_CLOUD_VMS
     709void UIChooserModel::sltHandleCloudAcquireInstancesTaskComplete(UITask *pTask)
     710{
     711    /* Call to base-class: */
     712    UIChooserAbstractModel::sltHandleCloudAcquireInstancesTaskComplete(pTask);
     713
     714    /* Rebuild tree for main root: */
     715    buildTreeForMainRoot();
     716    updateNavigationItemList();
     717    updateLayout();
     718}
     719#endif /* VBOX_GUI_WITH_CLOUD_VMS */
    707720
    708721void UIChooserModel::sltMakeSureCurrentItemVisible()
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserModel.h

    r82968 r83008  
    248248        virtual void sltReloadMachine(const QUuid &uId) /* override */;
    249249    /** @} */
     250
     251#ifdef VBOX_GUI_WITH_CLOUD_VMS
     252    /** @name Cloud stuff.
     253      * @{ */
     254        /** Handles acquire cloud machine task complete signal. */
     255        virtual void sltHandleCloudAcquireInstancesTaskComplete(UITask *pTask) /* override */;
     256    /** @} */
     257#endif /* VBOX_GUI_WITH_CLOUD_VMS */
    250258
    251259private slots:
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UITaskCloudAcquireInstances.cpp

    r82998 r83008  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UITask class implementation.
     3 * VBox Qt GUI - UITaskCloudAcquireInstances class implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2020 Oracle Corporation
     7 * Copyright (C) 2020 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1717
    1818/* GUI includes: */
    19 #include "UITask.h"
     19#include "UITaskCloudAcquireInstances.h"
    2020
    21 void UITask::start()
     21/* COM includes: */
     22#include "CProgress.h"
     23#include "CStringArray.h"
     24
     25
     26UITaskCloudAcquireInstances::UITaskCloudAcquireInstances(const CCloudClient &comCloudClient, UIChooserNode *pParentNode)
     27    : UITask(Type_CloudAcquireInstances)
     28    , m_comCloudClient(comCloudClient)
     29    , m_pParentNode(pParentNode)
    2230{
    23     /* Run task: */
    24     run();
    25     /* Notify listeners: */
    26     emit sigComplete(this);
    2731}
     32
     33QStringList UITaskCloudAcquireInstances::instanceNames() const
     34{
     35    m_mutex.lock();
     36    const QStringList instanceNames = m_instanceNames;
     37    m_mutex.unlock();
     38    return instanceNames;
     39}
     40
     41QStringList UITaskCloudAcquireInstances::instanceIds() const
     42{
     43    m_mutex.lock();
     44    const QStringList instanceIds = m_instanceIds;
     45    m_mutex.unlock();
     46    return instanceIds;
     47}
     48
     49CVirtualBoxErrorInfo UITaskCloudAcquireInstances::errorInfo()
     50{
     51    m_mutex.lock();
     52    CVirtualBoxErrorInfo comErrorInfo = m_comErrorInfo;
     53    m_mutex.unlock();
     54    return comErrorInfo;
     55}
     56
     57void UITaskCloudAcquireInstances::run()
     58{
     59    m_mutex.lock();
     60
     61    do
     62    {
     63        /* Gather VM names, ids and states.
     64         * Currently we are interested in Running and Stopped VMs only. */
     65        CStringArray comNames;
     66        CStringArray comIDs;
     67        const QVector<KCloudMachineState> cloudMachineStates  = QVector<KCloudMachineState>()
     68                                                             << KCloudMachineState_Running
     69                                                             << KCloudMachineState_Stopped;
     70
     71        /* Ask for cloud instance list: */
     72        CProgress comProgress = m_comCloudClient.ListInstances(cloudMachineStates, comNames, comIDs);
     73        if (!m_comCloudClient.isOk())
     74        {
     75            /// @todo pack error info to m_comErrorInfo
     76            break;
     77        }
     78
     79        /* Wait for "Acquire cloud instances" progress: */
     80        comProgress.WaitForCompletion(-1);
     81        if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
     82        {
     83            /// @todo pack error info to m_comErrorInfo
     84            break;
     85        }
     86
     87        /* Fetch acquired names/ids to lists: */
     88        m_instanceNames = comNames.GetValues().toList();
     89        m_instanceIds = comIDs.GetValues().toList();
     90    }
     91    while (0);
     92
     93    m_mutex.unlock();
     94}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UITaskCloudAcquireInstances.h

    r82998 r83008  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UITask class declaration.
     3 * VBox Qt GUI - UITaskCloudAcquireInstances class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2020 Oracle Corporation
     7 * Copyright (C) 2020 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef FEQT_INCLUDED_SRC_globals_UITask_h
    19 #define FEQT_INCLUDED_SRC_globals_UITask_h
     18#ifndef FEQT_INCLUDED_SRC_manager_chooser_UITaskCloudAcquireInstances_h
     19#define FEQT_INCLUDED_SRC_manager_chooser_UITaskCloudAcquireInstances_h
    2020#ifndef RT_WITHOUT_PRAGMA_ONCE
    2121# pragma once
     
    2323
    2424/* Qt includes: */
    25 #include <QObject>
     25#include <QMutex>
    2626
    2727/* GUI includes: */
    28 #include "UILibraryDefs.h"
     28#include "UITask.h"
    2929
    30 /** QObject extension used as worker-thread task interface.
    31   * Describes task to be handled by the UIThreadPool object. */
    32 class SHARED_LIBRARY_STUFF UITask : public QObject
     30/* COM includes: */
     31#include "COMEnums.h"
     32#include "CCloudClient.h"
     33#include "CVirtualBoxErrorInfo.h"
     34
     35/* Forward declaratiuons: */
     36class UIChooserNode;
     37
     38/** UITask extension used to load cloud instance list. */
     39class UITaskCloudAcquireInstances : public UITask
    3340{
    3441    Q_OBJECT;
    3542
    36 signals:
    37 
    38     /** Notifies listeners about @a pTask complete. */
    39     void sigComplete(UITask *pTask);
    40 
    4143public:
    4244
    43     /** Task types. */
    44     enum Type
    45     {
    46         Type_MediumEnumeration = 1,
    47         Type_DetailsPopulation = 2,
    48     };
     45    /** Constructs update task taking @a comCloudClient and @a pParentNode as data. */
     46    UITaskCloudAcquireInstances(const CCloudClient &comCloudClient, UIChooserNode *pParentNode);
    4947
    50     /** Constructs the task of passed @a enmType. */
    51     UITask(UITask::Type enmType) : m_enmType(enmType) {}
     48    /** Returns cloud client object. */
     49    CCloudClient cloudClient() const { return m_comCloudClient; }
     50    /** Returns parent node reference. */
     51    UIChooserNode *parentNode() const { return m_pParentNode; }
    5252
    53     /** Returns the type of the task. */
    54     UITask::Type type() const { return m_enmType; }
     53    /** Returns error info. */
     54    CVirtualBoxErrorInfo errorInfo();
    5555
    56     /** Starts the task. */
    57     void start();
     56    /** Returns the instance name list. */
     57    QStringList instanceNames() const;
     58    /** Returns the instance ID list. */
     59    QStringList instanceIds() const;
    5860
    5961protected:
    6062
    61     /** Contains the abstract task body. */
    62     virtual void run() = 0;
     63    /** Contains the task body. */
     64    virtual void run() /* override */;
    6365
    6466private:
    6567
    66     /** Holds the type of the task. */
    67     const UITask::Type  m_enmType;
     68    /** Holds the mutex to access m_guiMedium member. */
     69    mutable QMutex  m_mutex;
     70
     71    /** Holds the cloud client object. */
     72    CCloudClient   m_comCloudClient;
     73    /** Holds the parent node reference. */
     74    UIChooserNode *m_pParentNode;
     75
     76    /** Holds the error info object. */
     77    CVirtualBoxErrorInfo  m_comErrorInfo;
     78
     79    /** Holds the instance name list. */
     80    QStringList  m_instanceNames;
     81    /** Holds the instance ID list. */
     82    QStringList  m_instanceIds;
    6883};
    6984
    70 #endif /* !FEQT_INCLUDED_SRC_globals_UITask_h */
     85#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UITaskCloudAcquireInstances_h */
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