VirtualBox

Changeset 83108 in vbox for trunk


Ignore:
Timestamp:
Feb 18, 2020 3:29:54 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Moving UITaskCloudGetInstanceState class contents to separate files.

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

Legend:

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

    r83107 r83108  
    617617        src/manager/UIErrorPane.h \
    618618        src/manager/UITaskCloudAcquireInstances.h \
     619        src/manager/UITaskCloudGetInstanceState.h \
    619620        src/manager/UIToolPaneGlobal.h \
    620621        src/manager/UIToolPaneMachine.h \
     
    956957VirtualBox_QT_MOCSRCS = \
    957958        src/hostnetwork/UIHostNetworkManager.cpp \
    958         src/manager/UIVirtualMachineItemCloud.cpp \
    959959        src/manager/UIWelcomePane.cpp \
    960960        src/snapshots/UISnapshotDetailsWidget.cpp \
     
    10661066        src/manager/UIErrorPane.cpp \
    10671067        src/manager/UITaskCloudAcquireInstances.cpp \
     1068        src/manager/UITaskCloudGetInstanceState.cpp \
    10681069        src/manager/UIToolPaneGlobal.cpp \
    10691070        src/manager/UIToolPaneMachine.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UITask.h

    r83094 r83108  
    4747        Type_DetailsPopulation     = 2,
    4848        Type_CloudAcquireInstances = 3,
    49         Type_GetCloudInstanceState = 4,
     49        Type_CloudGetInstanceState = 4,
    5050    };
    5151
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UITaskCloudGetInstanceState.cpp

    r83107 r83108  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIVirtualMachineItemCloud class implementation.
     3 * VBox Qt GUI - UITaskCloudGetInstanceState class implementation.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-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 /* Qt includes: */
    19 #include <QTimer>
    20 
    2118/* GUI includes: */
    22 #include "UICloudMachine.h"
    2319#include "UICloudNetworkingStuff.h"
    24 #include "UICommon.h"
    25 #include "UIConverter.h"
    26 #include "UIIconPool.h"
    27 #include "UIMessageCenter.h"
    28 #include "UITask.h"
    29 #include "UIThreadPool.h"
    30 #include "UIVirtualMachineItemCloud.h"
    31 
    32 /* COM includes: */
    33 #include "CProgress.h"
     20#include "UITaskCloudGetInstanceState.h"
    3421
    3522
    36 /** UITask extension used to get cloud instance state async way. */
    37 class UITaskGetCloudInstanceState : public UITask
    38 {
    39     Q_OBJECT;
    40 
    41 public:
    42 
    43     /** Constructs task taking @a comCloudClient and @a strId as data.
    44       * @param  comCloudClient  Brings the cloud client object.
    45       * @param  strId           Brings the cloud VM id. */
    46     UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId);
    47 
    48     /** Returns the task result. */
    49     QString result() const;
    50 
    51 protected:
    52 
    53     /** Contains the task body. */
    54     virtual void run() /* override */;
    55 
    56 private:
    57 
    58     /** Holds the mutex to access result. */
    59     mutable QMutex  m_mutex;
    60 
    61     /** Holds the cloud client object. */
    62     CCloudClient  m_comCloudClient;
    63     /** Holds the cloud VM id. */
    64     QString       m_strId;
    65 
    66     /** Holds the error info object. */
    67     CVirtualBoxErrorInfo  m_comErrorInfo;
    68 
    69     /** Holds the task result. */
    70     QString  m_strResult;
    71 };
    72 
    73 
    74 /*********************************************************************************************************************************
    75 *   Class UITaskGetCloudInstanceState implementation.                                                                            *
    76 *********************************************************************************************************************************/
    77 
    78 UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId)
    79     : UITask(Type_GetCloudInstanceState)
     23UITaskCloudGetInstanceState::UITaskCloudGetInstanceState(const CCloudClient &comCloudClient, const QString &strId)
     24    : UITask(Type_CloudGetInstanceState)
    8025    , m_comCloudClient(comCloudClient)
    8126    , m_strId(strId)
     
    8328}
    8429
    85 QString UITaskGetCloudInstanceState::result() const
     30QString UITaskCloudGetInstanceState::result() const
    8631{
    8732    m_mutex.lock();
     
    9136}
    9237
    93 void UITaskGetCloudInstanceState::run()
     38CVirtualBoxErrorInfo UITaskCloudGetInstanceState::errorInfo()
     39{
     40    m_mutex.lock();
     41    CVirtualBoxErrorInfo comErrorInfo = m_comErrorInfo;
     42    m_mutex.unlock();
     43    return comErrorInfo;
     44}
     45
     46void UITaskCloudGetInstanceState::run()
    9447{
    9548    m_mutex.lock();
     
    9750    m_mutex.unlock();
    9851}
    99 
    100 
    101 /*********************************************************************************************************************************
    102 *   Class UIVirtualMachineItemCloud implementation.                                                                              *
    103 *********************************************************************************************************************************/
    104 
    105 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud()
    106     : UIVirtualMachineItem(ItemType_CloudFake)
    107     , m_pCloudMachine(0)
    108     , m_enmFakeCloudItemState(FakeCloudItemState_Loading)
    109     , m_pTask(0)
    110 {
    111     recache();
    112 }
    113 
    114 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(const UICloudMachine &guiCloudMachine)
    115     : UIVirtualMachineItem(ItemType_CloudReal)
    116     , m_pCloudMachine(new UICloudMachine(guiCloudMachine))
    117     , m_enmFakeCloudItemState(FakeCloudItemState_NotApplicable)
    118     , m_pTask(0)
    119 {
    120     recache();
    121 }
    122 
    123 UIVirtualMachineItemCloud::~UIVirtualMachineItemCloud()
    124 {
    125     delete m_pCloudMachine;
    126 }
    127 
    128 void UIVirtualMachineItemCloud::updateState(QWidget *pParent)
    129 {
    130     /* Make sure item is of real cloud type and is initialized: */
    131     AssertReturnVoid(itemType() == ItemType_CloudReal);
    132     AssertPtrReturnVoid(m_pCloudMachine);
    133 
    134     /* Acquire state: */
    135     const QString strState = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState,
    136                                              m_pCloudMachine->client(),
    137                                              m_strId,
    138                                              pParent);
    139 
    140     /* Update state: */
    141     updateState(strState);
    142 }
    143 
    144 void UIVirtualMachineItemCloud::updateStateAsync(bool fDelayed)
    145 {
    146     QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceStateTask()));
    147 }
    148 
    149 void UIVirtualMachineItemCloud::pause(QWidget *pParent)
    150 {
    151     pauseOrResume(true /* pause? */, pParent);
    152 }
    153 
    154 void UIVirtualMachineItemCloud::resume(QWidget *pParent)
    155 {
    156     pauseOrResume(false /* pause? */, pParent);
    157 }
    158 
    159 void UIVirtualMachineItemCloud::pauseOrResume(bool fPause, QWidget *pParent)
    160 {
    161     /* Acquire cloud client: */
    162     CCloudClient comCloudClient = m_pCloudMachine->client();
    163 
    164     /* Now execute async method: */
    165     CProgress comProgress;
    166     if (fPause)
    167         comProgress = comCloudClient.PauseInstance(m_strId);
    168     else
    169         comProgress = comCloudClient.StartInstance(m_strId);
    170     if (!comCloudClient.isOk())
    171         msgCenter().cannotAcquireCloudClientParameter(comCloudClient);
    172     else
    173     {
    174         /* Show progress: */
    175         /// @todo use proper pause icon
    176         if (fPause)
    177             msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Pause instance ..."),
    178                                                 ":/progress_reading_appliance_90px.png", pParent, 0);
    179         else
    180             msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Start instance ..."),
    181                                                 ":/progress_start_90px.png", pParent, 0);
    182         if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
    183             msgCenter().cannotAcquireCloudClientParameter(comProgress);
    184         else
    185             updateStateAsync(false /* delayed? */);
    186     }
    187 }
    188 
    189 void UIVirtualMachineItemCloud::recache()
    190 {
    191     /* Determine attributes which are always available: */
    192     if (itemType() == ItemType_CloudReal)
    193     {
    194         AssertPtrReturnVoid(m_pCloudMachine);
    195         m_strId = m_pCloudMachine->id();
    196         m_strName = m_pCloudMachine->name();
    197     }
    198 
    199     /* Now determine whether VM is accessible: */
    200     m_fAccessible = true;
    201     if (m_fAccessible)
    202     {
    203         /* Reset last access error information: */
    204         m_comAccessError = CVirtualBoxErrorInfo();
    205 
    206         /* Determine own VM attributes: */
    207         m_strOSTypeId = "Other";
    208 
    209         /* Determine VM states: */
    210         if (   itemType() == ItemType_CloudFake
    211             || m_enmMachineState == KMachineState_Null)
    212             m_enmMachineState = KMachineState_PoweredOff;
    213         m_strMachineStateName = gpConverter->toString(m_enmMachineState);
    214         if (itemType() == ItemType_CloudFake)
    215         {
    216             switch (m_enmFakeCloudItemState)
    217             {
    218                 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading:
    219                     m_machineStateIcon = UIIconPool::iconSet(":/state_loading_16px.png");
    220                     break;
    221                 case UIVirtualMachineItemCloud::FakeCloudItemState_Done:
    222                     m_machineStateIcon = UIIconPool::iconSet(":/vm_new_16px.png");
    223                     break;
    224                 default:
    225                     break;
    226             }
    227         }
    228         else
    229             m_machineStateIcon = gpConverter->toIcon(m_enmMachineState);
    230 
    231         /* Determine configuration access level: */
    232         m_enmConfigurationAccessLevel = ConfigurationAccessLevel_Null;
    233 
    234         /* Determine whether we should show this VM details: */
    235         m_fHasDetails = false;
    236     }
    237     else
    238     {
    239         /// @todo handle inaccessible cloud VM
    240     }
    241 
    242     /* Recache item pixmap: */
    243     recachePixmap();
    244 
    245     /* Retranslate finally: */
    246     retranslateUi();
    247 }
    248 
    249 void UIVirtualMachineItemCloud::recachePixmap()
    250 {
    251     /* If machine is accessible: */
    252     if (m_fAccessible)
    253     {
    254         /* We are using icon corresponding to cached guest OS type: */
    255         if (   itemType() == ItemType_CloudFake
    256             && fakeCloudItemState() == FakeCloudItemState_Loading)
    257             m_pixmap = uiCommon().vmGuestOSTypePixmapDefault("Cloud", &m_logicalPixmapSize);
    258         else
    259             m_pixmap = uiCommon().vmGuestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize);
    260     }
    261     /* Otherwise: */
    262     else
    263     {
    264         /// @todo handle inaccessible cloud VM
    265     }
    266 }
    267 
    268 bool UIVirtualMachineItemCloud::isItemEditable() const
    269 {
    270     return accessible();
    271 }
    272 
    273 bool UIVirtualMachineItemCloud::isItemSaved() const
    274 {
    275     return    accessible()
    276            && machineState() == KMachineState_Saved;
    277 }
    278 
    279 bool UIVirtualMachineItemCloud::isItemPoweredOff() const
    280 {
    281     return    accessible()
    282            && (   machineState() == KMachineState_PoweredOff
    283                || machineState() == KMachineState_Saved
    284                || machineState() == KMachineState_Teleported
    285                || machineState() == KMachineState_Aborted);
    286 }
    287 
    288 bool UIVirtualMachineItemCloud::isItemStarted() const
    289 {
    290     return    isItemRunning()
    291            || isItemPaused();
    292 }
    293 
    294 bool UIVirtualMachineItemCloud::isItemRunning() const
    295 {
    296     return    accessible()
    297            && (   machineState() == KMachineState_Running
    298                || machineState() == KMachineState_Teleporting
    299                || machineState() == KMachineState_LiveSnapshotting);
    300 }
    301 
    302 bool UIVirtualMachineItemCloud::isItemRunningHeadless() const
    303 {
    304     return isItemRunning();
    305 }
    306 
    307 bool UIVirtualMachineItemCloud::isItemPaused() const
    308 {
    309     return    accessible()
    310            && (   machineState() == KMachineState_Paused
    311                || machineState() == KMachineState_TeleportingPausedVM);
    312 }
    313 
    314 bool UIVirtualMachineItemCloud::isItemStuck() const
    315 {
    316     return    accessible()
    317            && machineState() == KMachineState_Stuck;
    318 }
    319 
    320 void UIVirtualMachineItemCloud::retranslateUi()
    321 {
    322     /* If machine is accessible: */
    323     if (m_fAccessible)
    324     {
    325         if (itemType() == ItemType_CloudFake)
    326         {
    327             /* Update machine/state name: */
    328             switch (m_enmFakeCloudItemState)
    329             {
    330                 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading:
    331                     m_strMachineStateName = tr("Loading ...");
    332                     break;
    333                 case UIVirtualMachineItemCloud::FakeCloudItemState_Done:
    334                     m_strMachineStateName = tr("Up-To-Date");
    335                     break;
    336                 default:
    337                     break;
    338             }
    339 
    340             /* Update tool-tip: */
    341             m_strToolTipText = m_strMachineStateName;
    342         }
    343         else
    344         {
    345             /* Update tool-tip: */
    346             m_strToolTipText = QString("<nobr><b>%1</b></nobr><br>"
    347                                        "<nobr>%2</nobr>")
    348                                        .arg(m_strName)
    349                                        .arg(gpConverter->toString(m_enmMachineState));
    350 
    351         }
    352     }
    353     /* Otherwise: */
    354     else
    355     {
    356         /* Update tool-tip: */
    357         m_strToolTipText = tr("<nobr><b>%1</b></nobr><br>"
    358                               "<nobr>Inaccessible</nobr>",
    359                               "Inaccessible VM tooltip (name)")
    360                               .arg(m_strName);
    361 
    362         /* We have our own translation for Null states: */
    363         m_strMachineStateName = tr("Inaccessible");
    364     }
    365 }
    366 
    367 void UIVirtualMachineItemCloud::sltCreateGetCloudInstanceStateTask()
    368 {
    369     /* Make sure item is of real cloud type and is initialized: */
    370     AssertReturnVoid(itemType() == ItemType_CloudReal);
    371     AssertPtrReturnVoid(m_pCloudMachine);
    372 
    373     /* Create and start task to acquire state async way only if there is no task yet: */
    374     if (!m_pTask)
    375     {
    376         m_pTask = new UITaskGetCloudInstanceState(m_pCloudMachine->client(), m_strId);
    377         connect(m_pTask, &UITask::sigComplete,
    378                 this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone);
    379         uiCommon().threadPool()->enqueueTask(m_pTask);
    380     }
    381 }
    382 
    383 void UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone(UITask *pTask)
    384 {
    385     /* Skip unrelated tasks: */
    386     if (!m_pTask || pTask != m_pTask)
    387         return;
    388 
    389     /* Mark our task handled: */
    390     m_pTask = 0;
    391 
    392     /* Cast task to corresponding sub-class: */
    393     UITaskGetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask);
    394 
    395     /* Update state: */
    396     updateState(pStateTask->result());
    397 }
    398 
    399 void UIVirtualMachineItemCloud::updateState(const QString &strState)
    400 {
    401     /* Prepare a map of known states: */
    402     QMap<QString, KMachineState> states;
    403     states["RUNNING"] = KMachineState_Running;
    404     states["STOPPED"] = KMachineState_Paused;
    405     states["STOPPING"] = KMachineState_Stopping;
    406     states["STARTING"] = KMachineState_Starting;
    407 
    408     /* Update our state value: */
    409     m_enmMachineState = states.value(strState, KMachineState_PoweredOff);
    410 
    411     /* Recache: */
    412     recache();
    413 
    414     /* Notify listeners finally: */
    415     emit sigStateChange();
    416 }
    417 
    418 
    419 #include "UIVirtualMachineItemCloud.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UITaskCloudGetInstanceState.h

    r83107 r83108  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIVirtualMachineItemCloud class implementation.
     3 * VBox Qt GUI - UITaskCloudGetInstanceState class declaration.
    44 */
    55
    66/*
    7  * Copyright (C) 2006-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_manager_UITaskCloudGetInstanceState_h
     19#define FEQT_INCLUDED_SRC_manager_UITaskCloudGetInstanceState_h
     20#ifndef RT_WITHOUT_PRAGMA_ONCE
     21# pragma once
     22#endif
     23
    1824/* Qt includes: */
    19 #include <QTimer>
     25#include <QMutex>
    2026
    2127/* GUI includes: */
    22 #include "UICloudMachine.h"
    23 #include "UICloudNetworkingStuff.h"
    24 #include "UICommon.h"
    25 #include "UIConverter.h"
    26 #include "UIIconPool.h"
    27 #include "UIMessageCenter.h"
    2828#include "UITask.h"
    29 #include "UIThreadPool.h"
    30 #include "UIVirtualMachineItemCloud.h"
    3129
    3230/* COM includes: */
    33 #include "CProgress.h"
     31#include "COMEnums.h"
     32#include "CCloudClient.h"
     33#include "CVirtualBoxErrorInfo.h"
    3434
    3535
    36 /** UITask extension used to get cloud instance state async way. */
    37 class UITaskGetCloudInstanceState : public UITask
     36/** UITask extension used to get cloud instance state. */
     37class UITaskCloudGetInstanceState : public UITask
    3838{
    3939    Q_OBJECT;
     
    4444      * @param  comCloudClient  Brings the cloud client object.
    4545      * @param  strId           Brings the cloud VM id. */
    46     UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId);
     46    UITaskCloudGetInstanceState(const CCloudClient &comCloudClient, const QString &strId);
     47
     48    /** Returns error info. */
     49    CVirtualBoxErrorInfo errorInfo();
    4750
    4851    /** Returns the task result. */
     
    7174};
    7275
    73 
    74 /*********************************************************************************************************************************
    75 *   Class UITaskGetCloudInstanceState implementation.                                                                            *
    76 *********************************************************************************************************************************/
    77 
    78 UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId)
    79     : UITask(Type_GetCloudInstanceState)
    80     , m_comCloudClient(comCloudClient)
    81     , m_strId(strId)
    82 {
    83 }
    84 
    85 QString UITaskGetCloudInstanceState::result() const
    86 {
    87     m_mutex.lock();
    88     const QString strResult = m_strResult;
    89     m_mutex.unlock();
    90     return strResult;
    91 }
    92 
    93 void UITaskGetCloudInstanceState::run()
    94 {
    95     m_mutex.lock();
    96     m_strResult = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, m_comCloudClient, m_strId);
    97     m_mutex.unlock();
    98 }
    99 
    100 
    101 /*********************************************************************************************************************************
    102 *   Class UIVirtualMachineItemCloud implementation.                                                                              *
    103 *********************************************************************************************************************************/
    104 
    105 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud()
    106     : UIVirtualMachineItem(ItemType_CloudFake)
    107     , m_pCloudMachine(0)
    108     , m_enmFakeCloudItemState(FakeCloudItemState_Loading)
    109     , m_pTask(0)
    110 {
    111     recache();
    112 }
    113 
    114 UIVirtualMachineItemCloud::UIVirtualMachineItemCloud(const UICloudMachine &guiCloudMachine)
    115     : UIVirtualMachineItem(ItemType_CloudReal)
    116     , m_pCloudMachine(new UICloudMachine(guiCloudMachine))
    117     , m_enmFakeCloudItemState(FakeCloudItemState_NotApplicable)
    118     , m_pTask(0)
    119 {
    120     recache();
    121 }
    122 
    123 UIVirtualMachineItemCloud::~UIVirtualMachineItemCloud()
    124 {
    125     delete m_pCloudMachine;
    126 }
    127 
    128 void UIVirtualMachineItemCloud::updateState(QWidget *pParent)
    129 {
    130     /* Make sure item is of real cloud type and is initialized: */
    131     AssertReturnVoid(itemType() == ItemType_CloudReal);
    132     AssertPtrReturnVoid(m_pCloudMachine);
    133 
    134     /* Acquire state: */
    135     const QString strState = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState,
    136                                              m_pCloudMachine->client(),
    137                                              m_strId,
    138                                              pParent);
    139 
    140     /* Update state: */
    141     updateState(strState);
    142 }
    143 
    144 void UIVirtualMachineItemCloud::updateStateAsync(bool fDelayed)
    145 {
    146     QTimer::singleShot(fDelayed ? 10000 : 0, this, SLOT(sltCreateGetCloudInstanceStateTask()));
    147 }
    148 
    149 void UIVirtualMachineItemCloud::pause(QWidget *pParent)
    150 {
    151     pauseOrResume(true /* pause? */, pParent);
    152 }
    153 
    154 void UIVirtualMachineItemCloud::resume(QWidget *pParent)
    155 {
    156     pauseOrResume(false /* pause? */, pParent);
    157 }
    158 
    159 void UIVirtualMachineItemCloud::pauseOrResume(bool fPause, QWidget *pParent)
    160 {
    161     /* Acquire cloud client: */
    162     CCloudClient comCloudClient = m_pCloudMachine->client();
    163 
    164     /* Now execute async method: */
    165     CProgress comProgress;
    166     if (fPause)
    167         comProgress = comCloudClient.PauseInstance(m_strId);
    168     else
    169         comProgress = comCloudClient.StartInstance(m_strId);
    170     if (!comCloudClient.isOk())
    171         msgCenter().cannotAcquireCloudClientParameter(comCloudClient);
    172     else
    173     {
    174         /* Show progress: */
    175         /// @todo use proper pause icon
    176         if (fPause)
    177             msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Pause instance ..."),
    178                                                 ":/progress_reading_appliance_90px.png", pParent, 0);
    179         else
    180             msgCenter().showModalProgressDialog(comProgress, UICommon::tr("Start instance ..."),
    181                                                 ":/progress_start_90px.png", pParent, 0);
    182         if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
    183             msgCenter().cannotAcquireCloudClientParameter(comProgress);
    184         else
    185             updateStateAsync(false /* delayed? */);
    186     }
    187 }
    188 
    189 void UIVirtualMachineItemCloud::recache()
    190 {
    191     /* Determine attributes which are always available: */
    192     if (itemType() == ItemType_CloudReal)
    193     {
    194         AssertPtrReturnVoid(m_pCloudMachine);
    195         m_strId = m_pCloudMachine->id();
    196         m_strName = m_pCloudMachine->name();
    197     }
    198 
    199     /* Now determine whether VM is accessible: */
    200     m_fAccessible = true;
    201     if (m_fAccessible)
    202     {
    203         /* Reset last access error information: */
    204         m_comAccessError = CVirtualBoxErrorInfo();
    205 
    206         /* Determine own VM attributes: */
    207         m_strOSTypeId = "Other";
    208 
    209         /* Determine VM states: */
    210         if (   itemType() == ItemType_CloudFake
    211             || m_enmMachineState == KMachineState_Null)
    212             m_enmMachineState = KMachineState_PoweredOff;
    213         m_strMachineStateName = gpConverter->toString(m_enmMachineState);
    214         if (itemType() == ItemType_CloudFake)
    215         {
    216             switch (m_enmFakeCloudItemState)
    217             {
    218                 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading:
    219                     m_machineStateIcon = UIIconPool::iconSet(":/state_loading_16px.png");
    220                     break;
    221                 case UIVirtualMachineItemCloud::FakeCloudItemState_Done:
    222                     m_machineStateIcon = UIIconPool::iconSet(":/vm_new_16px.png");
    223                     break;
    224                 default:
    225                     break;
    226             }
    227         }
    228         else
    229             m_machineStateIcon = gpConverter->toIcon(m_enmMachineState);
    230 
    231         /* Determine configuration access level: */
    232         m_enmConfigurationAccessLevel = ConfigurationAccessLevel_Null;
    233 
    234         /* Determine whether we should show this VM details: */
    235         m_fHasDetails = false;
    236     }
    237     else
    238     {
    239         /// @todo handle inaccessible cloud VM
    240     }
    241 
    242     /* Recache item pixmap: */
    243     recachePixmap();
    244 
    245     /* Retranslate finally: */
    246     retranslateUi();
    247 }
    248 
    249 void UIVirtualMachineItemCloud::recachePixmap()
    250 {
    251     /* If machine is accessible: */
    252     if (m_fAccessible)
    253     {
    254         /* We are using icon corresponding to cached guest OS type: */
    255         if (   itemType() == ItemType_CloudFake
    256             && fakeCloudItemState() == FakeCloudItemState_Loading)
    257             m_pixmap = uiCommon().vmGuestOSTypePixmapDefault("Cloud", &m_logicalPixmapSize);
    258         else
    259             m_pixmap = uiCommon().vmGuestOSTypePixmapDefault(m_strOSTypeId, &m_logicalPixmapSize);
    260     }
    261     /* Otherwise: */
    262     else
    263     {
    264         /// @todo handle inaccessible cloud VM
    265     }
    266 }
    267 
    268 bool UIVirtualMachineItemCloud::isItemEditable() const
    269 {
    270     return accessible();
    271 }
    272 
    273 bool UIVirtualMachineItemCloud::isItemSaved() const
    274 {
    275     return    accessible()
    276            && machineState() == KMachineState_Saved;
    277 }
    278 
    279 bool UIVirtualMachineItemCloud::isItemPoweredOff() const
    280 {
    281     return    accessible()
    282            && (   machineState() == KMachineState_PoweredOff
    283                || machineState() == KMachineState_Saved
    284                || machineState() == KMachineState_Teleported
    285                || machineState() == KMachineState_Aborted);
    286 }
    287 
    288 bool UIVirtualMachineItemCloud::isItemStarted() const
    289 {
    290     return    isItemRunning()
    291            || isItemPaused();
    292 }
    293 
    294 bool UIVirtualMachineItemCloud::isItemRunning() const
    295 {
    296     return    accessible()
    297            && (   machineState() == KMachineState_Running
    298                || machineState() == KMachineState_Teleporting
    299                || machineState() == KMachineState_LiveSnapshotting);
    300 }
    301 
    302 bool UIVirtualMachineItemCloud::isItemRunningHeadless() const
    303 {
    304     return isItemRunning();
    305 }
    306 
    307 bool UIVirtualMachineItemCloud::isItemPaused() const
    308 {
    309     return    accessible()
    310            && (   machineState() == KMachineState_Paused
    311                || machineState() == KMachineState_TeleportingPausedVM);
    312 }
    313 
    314 bool UIVirtualMachineItemCloud::isItemStuck() const
    315 {
    316     return    accessible()
    317            && machineState() == KMachineState_Stuck;
    318 }
    319 
    320 void UIVirtualMachineItemCloud::retranslateUi()
    321 {
    322     /* If machine is accessible: */
    323     if (m_fAccessible)
    324     {
    325         if (itemType() == ItemType_CloudFake)
    326         {
    327             /* Update machine/state name: */
    328             switch (m_enmFakeCloudItemState)
    329             {
    330                 case UIVirtualMachineItemCloud::FakeCloudItemState_Loading:
    331                     m_strMachineStateName = tr("Loading ...");
    332                     break;
    333                 case UIVirtualMachineItemCloud::FakeCloudItemState_Done:
    334                     m_strMachineStateName = tr("Up-To-Date");
    335                     break;
    336                 default:
    337                     break;
    338             }
    339 
    340             /* Update tool-tip: */
    341             m_strToolTipText = m_strMachineStateName;
    342         }
    343         else
    344         {
    345             /* Update tool-tip: */
    346             m_strToolTipText = QString("<nobr><b>%1</b></nobr><br>"
    347                                        "<nobr>%2</nobr>")
    348                                        .arg(m_strName)
    349                                        .arg(gpConverter->toString(m_enmMachineState));
    350 
    351         }
    352     }
    353     /* Otherwise: */
    354     else
    355     {
    356         /* Update tool-tip: */
    357         m_strToolTipText = tr("<nobr><b>%1</b></nobr><br>"
    358                               "<nobr>Inaccessible</nobr>",
    359                               "Inaccessible VM tooltip (name)")
    360                               .arg(m_strName);
    361 
    362         /* We have our own translation for Null states: */
    363         m_strMachineStateName = tr("Inaccessible");
    364     }
    365 }
    366 
    367 void UIVirtualMachineItemCloud::sltCreateGetCloudInstanceStateTask()
    368 {
    369     /* Make sure item is of real cloud type and is initialized: */
    370     AssertReturnVoid(itemType() == ItemType_CloudReal);
    371     AssertPtrReturnVoid(m_pCloudMachine);
    372 
    373     /* Create and start task to acquire state async way only if there is no task yet: */
    374     if (!m_pTask)
    375     {
    376         m_pTask = new UITaskGetCloudInstanceState(m_pCloudMachine->client(), m_strId);
    377         connect(m_pTask, &UITask::sigComplete,
    378                 this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone);
    379         uiCommon().threadPool()->enqueueTask(m_pTask);
    380     }
    381 }
    382 
    383 void UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone(UITask *pTask)
    384 {
    385     /* Skip unrelated tasks: */
    386     if (!m_pTask || pTask != m_pTask)
    387         return;
    388 
    389     /* Mark our task handled: */
    390     m_pTask = 0;
    391 
    392     /* Cast task to corresponding sub-class: */
    393     UITaskGetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask);
    394 
    395     /* Update state: */
    396     updateState(pStateTask->result());
    397 }
    398 
    399 void UIVirtualMachineItemCloud::updateState(const QString &strState)
    400 {
    401     /* Prepare a map of known states: */
    402     QMap<QString, KMachineState> states;
    403     states["RUNNING"] = KMachineState_Running;
    404     states["STOPPED"] = KMachineState_Paused;
    405     states["STOPPING"] = KMachineState_Stopping;
    406     states["STARTING"] = KMachineState_Starting;
    407 
    408     /* Update our state value: */
    409     m_enmMachineState = states.value(strState, KMachineState_PoweredOff);
    410 
    411     /* Recache: */
    412     recache();
    413 
    414     /* Notify listeners finally: */
    415     emit sigStateChange();
    416 }
    417 
    418 
    419 #include "UIVirtualMachineItemCloud.moc"
     76#endif /* !FEQT_INCLUDED_SRC_manager_UITaskCloudGetInstanceState_h */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp

    r83107 r83108  
    2626#include "UIIconPool.h"
    2727#include "UIMessageCenter.h"
    28 #include "UITask.h"
     28#include "UITaskCloudGetInstanceState.h"
    2929#include "UIThreadPool.h"
    3030#include "UIVirtualMachineItemCloud.h"
     
    3333#include "CProgress.h"
    3434
    35 
    36 /** UITask extension used to get cloud instance state async way. */
    37 class UITaskGetCloudInstanceState : public UITask
    38 {
    39     Q_OBJECT;
    40 
    41 public:
    42 
    43     /** Constructs task taking @a comCloudClient and @a strId as data.
    44       * @param  comCloudClient  Brings the cloud client object.
    45       * @param  strId           Brings the cloud VM id. */
    46     UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId);
    47 
    48     /** Returns the task result. */
    49     QString result() const;
    50 
    51 protected:
    52 
    53     /** Contains the task body. */
    54     virtual void run() /* override */;
    55 
    56 private:
    57 
    58     /** Holds the mutex to access result. */
    59     mutable QMutex  m_mutex;
    60 
    61     /** Holds the cloud client object. */
    62     CCloudClient  m_comCloudClient;
    63     /** Holds the cloud VM id. */
    64     QString       m_strId;
    65 
    66     /** Holds the error info object. */
    67     CVirtualBoxErrorInfo  m_comErrorInfo;
    68 
    69     /** Holds the task result. */
    70     QString  m_strResult;
    71 };
    72 
    73 
    74 /*********************************************************************************************************************************
    75 *   Class UITaskGetCloudInstanceState implementation.                                                                            *
    76 *********************************************************************************************************************************/
    77 
    78 UITaskGetCloudInstanceState::UITaskGetCloudInstanceState(const CCloudClient &comCloudClient, const QString &strId)
    79     : UITask(Type_GetCloudInstanceState)
    80     , m_comCloudClient(comCloudClient)
    81     , m_strId(strId)
    82 {
    83 }
    84 
    85 QString UITaskGetCloudInstanceState::result() const
    86 {
    87     m_mutex.lock();
    88     const QString strResult = m_strResult;
    89     m_mutex.unlock();
    90     return strResult;
    91 }
    92 
    93 void UITaskGetCloudInstanceState::run()
    94 {
    95     m_mutex.lock();
    96     m_strResult = getInstanceInfo(KVirtualSystemDescriptionType_CloudInstanceState, m_comCloudClient, m_strId);
    97     m_mutex.unlock();
    98 }
    99 
    100 
    101 /*********************************************************************************************************************************
    102 *   Class UIVirtualMachineItemCloud implementation.                                                                              *
    103 *********************************************************************************************************************************/
    10435
    10536UIVirtualMachineItemCloud::UIVirtualMachineItemCloud()
     
    374305    if (!m_pTask)
    375306    {
    376         m_pTask = new UITaskGetCloudInstanceState(m_pCloudMachine->client(), m_strId);
     307        m_pTask = new UITaskCloudGetInstanceState(m_pCloudMachine->client(), m_strId);
    377308        connect(m_pTask, &UITask::sigComplete,
    378309                this, &UIVirtualMachineItemCloud::sltHandleGetCloudInstanceStateDone);
     
    391322
    392323    /* Cast task to corresponding sub-class: */
    393     UITaskGetCloudInstanceState *pStateTask = static_cast<UITaskGetCloudInstanceState*>(pTask);
     324    UITaskCloudGetInstanceState *pStateTask = static_cast<UITaskCloudGetInstanceState*>(pTask);
    394325
    395326    /* Update state: */
     
    415346    emit sigStateChange();
    416347}
    417 
    418 
    419 #include "UIVirtualMachineItemCloud.moc"
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.h

    r83095 r83108  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIVirtualMachineItemCloud class declarations.
     3 * VBox Qt GUI - UIVirtualMachineItemCloud class declaration.
    44 */
    55
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemLocal.h

    r82944 r83108  
    11/* $Id$ */
    22/** @file
    3  * VBox Qt GUI - UIVirtualMachineItemLocal class declarations.
     3 * VBox Qt GUI - UIVirtualMachineItemLocal class declaration.
    44 */
    55
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