VirtualBox

Changeset 84189 in vbox


Ignore:
Timestamp:
May 7, 2020 3:13:27 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Rework cloud VM item to use own pool of possible states, based on KCloudMachineState enum; Temporary toCloudMachineState converter function was introduced for consistency, to be moved when CCloudMachine::GetState will be returning proper value type.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackend.h

    r83494 r84189  
    129129
    130130/* Declare COM canConvert specializations: */
     131template<> SHARED_LIBRARY_STUFF bool canConvert<KCloudMachineState>();
    131132template<> SHARED_LIBRARY_STUFF bool canConvert<KMachineState>();
    132133template<> SHARED_LIBRARY_STUFF bool canConvert<KSessionState>();
     
    273274
    274275/* Declare COM conversion specializations: */
     276template<> SHARED_LIBRARY_STUFF QIcon toIcon(const KCloudMachineState &state);
     277template<> SHARED_LIBRARY_STUFF QString toString(const KCloudMachineState &state);
    275278template<> SHARED_LIBRARY_STUFF QColor toColor(const KMachineState &state);
    276279template<> SHARED_LIBRARY_STUFF QIcon toIcon(const KMachineState &state);
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackendCOM.cpp

    r82968 r84189  
    3030/* Determines if <Object of type X> can be converted to object of other type.
    3131 * These functions returns 'true' for all allowed conversions. */
     32template<> bool canConvert<KCloudMachineState>() { return true; }
    3233template<> bool canConvert<KMachineState>() { return true; }
    3334template<> bool canConvert<KSessionState>() { return true; }
     
    5455template<> bool canConvert<KChipsetType>() { return true; }
    5556template<> bool canConvert<KNATProtocol>() { return true; }
     57
     58/* QIcon <= KCloudMachineState: */
     59template<> QIcon toIcon(const KCloudMachineState &state)
     60{
     61    switch (state)
     62    {
     63        case KCloudMachineState_Provisioning:  return UIIconPool::iconSet(":/state_running_16px.png");
     64        case KCloudMachineState_Running:       return UIIconPool::iconSet(":/state_running_16px.png");
     65        case KCloudMachineState_Starting:      return UIIconPool::iconSet(":/state_running_16px.png");
     66        case KCloudMachineState_Stopping:      return UIIconPool::iconSet(":/state_saving_16px.png");
     67        case KCloudMachineState_Stopped:       return UIIconPool::iconSet(":/state_saved_16px.png");
     68        case KCloudMachineState_CreatingImage: return UIIconPool::iconSet(":/state_saved_16px.png");
     69        case KCloudMachineState_Terminating:   return UIIconPool::iconSet(":/state_discarding_16px.png");
     70        case KCloudMachineState_Terminated:    return UIIconPool::iconSet(":/state_powered_off_16px.png");
     71        default: AssertMsgFailed(("No icon for %d", state)); break;
     72    }
     73    return QIcon();
     74}
     75
     76/* QString <= KCloudMachineState: */
     77template<> QString toString(const KCloudMachineState &state)
     78{
     79    switch (state)
     80    {
     81        case KCloudMachineState_Provisioning:  return QApplication::translate("UICommon", "Provisioning", "CloudMachineState");
     82        case KCloudMachineState_Running:       return QApplication::translate("UICommon", "Running", "CloudMachineState");
     83        case KCloudMachineState_Starting:      return QApplication::translate("UICommon", "Starting", "CloudMachineState");
     84        case KCloudMachineState_Stopping:      return QApplication::translate("UICommon", "Stopping", "CloudMachineState");
     85        case KCloudMachineState_Stopped:       return QApplication::translate("UICommon", "Stopped", "CloudMachineState");
     86        case KCloudMachineState_CreatingImage: return QApplication::translate("UICommon", "Creating Image", "CloudMachineState");
     87        case KCloudMachineState_Terminating:   return QApplication::translate("UICommon", "Terminating", "CloudMachineState");
     88        case KCloudMachineState_Terminated:    return QApplication::translate("UICommon", "Terminated", "CloudMachineState");
     89        default: AssertMsgFailed(("No text for %d", state)); break;
     90    }
     91    return QString();
     92}
    5693
    5794/* QColor <= KMachineState: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r84188 r84189  
    810810            continue;
    811811
    812         /* Get machine item state: */
    813         const KMachineState enmState = pItem->machineState();
     812        /* Get local machine item state: */
     813        UIVirtualMachineItemLocal *pLocalItem = pItem->toLocal();
     814        AssertPtrReturnVoid(pLocalItem);
     815        const KMachineState enmState = pLocalItem->machineState();
    814816
    815817        /* Check if current item could be paused/resumed: */
     
    937939        /* Get session machine: */
    938940        CMachine comMachine = comSession.GetMachine();
    939         /* Get machine item state: */
    940         const KMachineState enmState = pItem->machineState();
     941
     942        /* Get local machine item state: */
     943        UIVirtualMachineItemLocal *pLocalItem = pItem->toLocal();
     944        AssertPtrReturnVoid(pLocalItem);
     945        const KMachineState enmState = pLocalItem->machineState();
     946
    941947        /* Pause VM first if necessary: */
    942948        if (enmState != KMachineState_Paused)
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItem.cpp

    r83921 r84189  
    2828    : m_enmType(enmType)
    2929    , m_fAccessible(false)
    30     , m_enmMachineState(KMachineState_Null)
    3130    , m_enmConfigurationAccessLevel(ConfigurationAccessLevel_Null)
    3231    , m_fHasDetails(false)
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItem.h

    r84102 r84189  
    8585    /** @name State attributes.
    8686      * @{ */
    87         /** Returns cached machine state. */
    88         KMachineState machineState() const { return m_enmMachineState; }
    8987        /** Returns cached machine state name. */
    9088        QString machineStateName() const { return m_strMachineStateName; }
     
    172170    /** @name State attributes.
    173171      * @{ */
    174         /** Holds cached machine state. */
    175         KMachineState  m_enmMachineState;
    176172        /** Holds cached machine state name. */
    177173        QString        m_strMachineStateName;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.cpp

    r84182 r84189  
    3737UIVirtualMachineItemCloud::UIVirtualMachineItemCloud()
    3838    : UIVirtualMachineItem(UIVirtualMachineItemType_CloudFake)
     39    , m_enmMachineState(KCloudMachineState_Invalid)
    3940    , m_enmFakeCloudItemState(UIFakeCloudVirtualMachineItemState_Loading)
    4041    , m_pTask(0)
     
    4647    : UIVirtualMachineItem(UIVirtualMachineItemType_CloudReal)
    4748    , m_comCloudMachine(comCloudMachine)
     49    , m_enmMachineState(KCloudMachineState_Invalid)
    4850    , m_enmFakeCloudItemState(UIFakeCloudVirtualMachineItemState_NotApplicable)
    4951    , m_pTask(0)
     
    9496
    9597            /* Determine VM states: */
    96             m_enmMachineState = KMachineState_PoweredOff;
     98            m_enmMachineState = KCloudMachineState_Stopped;
    9799            m_strMachineStateName = gpConverter->toString(m_enmMachineState);
    98100            switch (m_enmFakeCloudItemState)
     
    133135
    134136            /* Determine VM states: */
    135             m_enmMachineState = m_fAccessible ? m_comCloudMachine.GetState() : KMachineState_PoweredOff;
     137            m_enmMachineState = m_fAccessible ? toCloudMachineState(m_comCloudMachine.GetState()) : KCloudMachineState_Stopped;
    136138            m_strMachineStateName = gpConverter->toString(m_enmMachineState);
    137139            m_machineStateIcon = gpConverter->toIcon(m_enmMachineState);
     
    183185bool UIVirtualMachineItemCloud::isItemSaved() const
    184186{
     187    return false;
     188}
     189
     190bool UIVirtualMachineItemCloud::isItemPoweredOff() const
     191{
    185192    return    accessible()
    186            && machineState() == KMachineState_Saved;
    187 }
    188 
    189 bool UIVirtualMachineItemCloud::isItemPoweredOff() const
    190 {
    191     return    accessible()
    192            && (   machineState() == KMachineState_PoweredOff
    193                || machineState() == KMachineState_Saved
    194                || machineState() == KMachineState_Teleported
    195                || machineState() == KMachineState_Aborted);
     193           && (   machineState() == KCloudMachineState_Stopped
     194               || machineState() == KCloudMachineState_Terminated);
    196195}
    197196
     
    205204{
    206205    return    accessible()
    207            && (   machineState() == KMachineState_Running
    208                || machineState() == KMachineState_Teleporting
    209                || machineState() == KMachineState_LiveSnapshotting);
     206           && machineState() == KCloudMachineState_Running;
    210207}
    211208
     
    217214bool UIVirtualMachineItemCloud::isItemPaused() const
    218215{
    219     return    accessible()
    220            && (   machineState() == KMachineState_Paused
    221                || machineState() == KMachineState_TeleportingPausedVM);
     216    return false;
    222217}
    223218
    224219bool UIVirtualMachineItemCloud::isItemStuck() const
    225220{
    226     return    accessible()
    227            && machineState() == KMachineState_Stuck;
     221    return false;
    228222}
    229223
     
    309303    emit sigStateChange();
    310304}
     305
     306/* static */
     307KCloudMachineState UIVirtualMachineItemCloud::toCloudMachineState(KMachineState enmState)
     308{
     309    switch (enmState)
     310    {
     311        case KMachineState_Starting:   return KCloudMachineState_Starting;
     312        case KMachineState_Running:    return KCloudMachineState_Running;
     313        case KMachineState_Stopping:   return KCloudMachineState_Stopping;
     314        case KMachineState_PoweredOff: return KCloudMachineState_Stopped;
     315        default:                       return KCloudMachineState_Stopped;
     316    }
     317}
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemCloud.h

    r84182 r84189  
    5959    /** @name Data attributes.
    6060      * @{ */
     61        /** Returns cached machine state. */
     62        KCloudMachineState machineState() const { return m_enmMachineState; }
     63
    6164        /** Defines fake cloud item @a enmState. */
    6265        void setFakeCloudItemState(UIFakeCloudVirtualMachineItemState enmState);
     
    122125private:
    123126
     127    /** Temporary! Converts state from KMachineState to KCloudMachineState. */
     128    static KCloudMachineState toCloudMachineState(KMachineState enmState);
     129
    124130    /** @name Arguments.
    125131      * @{ */
     
    130136    /** @name Data attributes.
    131137      * @{ */
     138        /** Holds cached machine state. */
     139        KCloudMachineState  m_enmMachineState;
     140
    132141        /** Holds fake cloud item state. */
    133142        UIFakeCloudVirtualMachineItemState  m_enmFakeCloudItemState;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemLocal.cpp

    r84102 r84189  
    4343    , m_comMachine(comMachine)
    4444    , m_cSnaphot(0)
     45    , m_enmMachineState(KMachineState_Null)
    4546    , m_enmSessionState(KSessionState_Null)
    4647{
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItemLocal.h

    r84102 r84189  
    6767    /** @name State attributes.
    6868      * @{ */
     69        /** Returns cached machine state. */
     70        KMachineState machineState() const { return m_enmMachineState; }
    6971        /** Returns cached session state. */
    7072        KSessionState sessionState() const { return m_enmSessionState; }
     
    148150    /** @name State attributes.
    149151      * @{ */
     152        /** Holds cached machine state. */
     153        KMachineState  m_enmMachineState;
    150154        /** Holds cached session state. */
    151155        KSessionState  m_enmSessionState;
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemMachine.cpp

    r84188 r84189  
    9797
    9898    /* Acquire local machine state: */
    99     const KMachineState enmState = cache()->machineState();
     99    AssertPtrReturn(cache()->toLocal(), true);
     100    const KMachineState enmState = cache()->toLocal()->machineState();
    100101    return    enmState != KMachineState_PoweredOff
    101102           && enmState != KMachineState_Saved
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