VirtualBox

Changeset 90855 in vbox


Ignore:
Timestamp:
Aug 24, 2021 5:51:34 PM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10067: Reworking r145993; UINotificationProgressMachineSaveState should now be usable from within Runtime UI as well.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r90796 r90855  
    16801680        /* Sanity check: */
    16811681        AssertPtrReturnVoid(pItem);
     1682        AssertPtrReturnVoid(pItem->toLocal());
    16821683
    16831684        /* Check if current item could be saved: */
     
    16861687
    16871688        /* Saving VM state: */
    1688         UINotificationProgressMachineSaveState *pNotification = new UINotificationProgressMachineSaveState(pItem->id());
     1689        UINotificationProgressMachineSaveState *pNotification = new UINotificationProgressMachineSaveState(pItem->toLocal()->machine());
    16891690        gpNotificationCenter->append(pNotification);
    16901691    }
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.cpp

    r90796 r90855  
    859859*********************************************************************************************************************************/
    860860
    861 UINotificationProgressMachineSaveState::UINotificationProgressMachineSaveState(const QUuid &uId)
    862     : m_uId(uId)
     861UINotificationProgressMachineSaveState::UINotificationProgressMachineSaveState(const CMachine &comMachine)
     862    : m_comMachine(comMachine)
    863863{
    864864    connect(this, &UINotificationProgress::sigProgressFinished,
     
    878878CProgress UINotificationProgressMachineSaveState::createProgress(COMResult &comResult)
    879879{
    880     /* Open a session thru which we will modify the machine: */
    881     m_comSession = uiCommon().openExistingSession(m_uId);
    882     if (m_comSession.isNull())
    883         return CProgress();
    884 
    885     /* Get session machine: */
    886     CMachine comMachine = m_comSession.GetMachine();
    887     if (!m_comSession.isOk())
    888     {
    889         comResult = m_comSession;
     880    /* Acquire VM id: */
     881    const QUuid uId = m_comMachine.GetId();
     882    if (!m_comMachine.isOk())
     883    {
     884        comResult = m_comMachine;
     885        return CProgress();
     886    }
     887
     888    /* Acquire VM name: */
     889    m_strName = m_comMachine.GetName();
     890    if (!m_comMachine.isOk())
     891    {
     892        comResult = m_comMachine;
     893        return CProgress();
     894    }
     895
     896    /* Prepare machine to save: */
     897    CMachine comMachine = m_comMachine;
     898
     899    /* For Manager UI: */
     900    switch (uiCommon().uiType())
     901    {
     902        case UICommon::UIType_SelectorUI:
     903        {
     904            /* Open a session thru which we will modify the machine: */
     905            m_comSession = uiCommon().openExistingSession(uId);
     906            if (m_comSession.isNull())
     907                return CProgress();
     908
     909            /* Get session machine: */
     910            comMachine = m_comSession.GetMachine();
     911            if (!m_comSession.isOk())
     912            {
     913                comResult = m_comSession;
     914                m_comSession.UnlockMachine();
     915                return CProgress();
     916            }
     917
     918            /* Get machine state: */
     919            const KMachineState enmState = comMachine.GetState();
     920            if (!comMachine.isOk())
     921            {
     922                comResult = comMachine;
     923                m_comSession.UnlockMachine();
     924                return CProgress();
     925            }
     926
     927            /* If VM isn't yet paused: */
     928            if (enmState != KMachineState_Paused)
     929            {
     930                /* Get session console: */
     931                CConsole comConsole = m_comSession.GetConsole();
     932                if (!m_comSession.isOk())
     933                {
     934                    comResult = m_comSession;
     935                    m_comSession.UnlockMachine();
     936                    return CProgress();
     937                }
     938
     939                /* Pause VM first: */
     940                comConsole.Pause();
     941                if (!comConsole.isOk())
     942                {
     943                    comResult = comConsole;
     944                    m_comSession.UnlockMachine();
     945                    return CProgress();
     946                }
     947            }
     948
     949            break;
     950        }
     951        default:
     952            break;
     953    }
     954
     955    /* Initialize progress-wrapper: */
     956    CProgress comProgress = comMachine.SaveState();
     957    /* Store COM result: */
     958    comResult = comMachine;
     959    /* Return progress-wrapper: */
     960    return comProgress;
     961}
     962
     963void UINotificationProgressMachineSaveState::sltHandleProgressFinished()
     964{
     965    /* Unlock session finally: */
     966    if (m_comSession.isNotNull())
    890967        m_comSession.UnlockMachine();
    891         return CProgress();
    892     }
    893 
    894     /* Acquire VM name: */
    895     m_strName = comMachine.GetName();
    896     if (!comMachine.isOk())
    897     {
    898         comResult = comMachine;
    899         m_comSession.UnlockMachine();
    900         return CProgress();
    901     }
    902 
    903     /* Get machine state: */
    904     const KMachineState enmState = comMachine.GetState();
    905     if (!comMachine.isOk())
    906     {
    907         comResult = comMachine;
    908         m_comSession.UnlockMachine();
    909         return CProgress();
    910     }
    911 
    912     /* If VM isn't yet paused: */
    913     if (enmState != KMachineState_Paused)
    914     {
    915         /* Get session console: */
    916         CConsole comConsole = m_comSession.GetConsole();
    917         if (!m_comSession.isOk())
    918         {
    919             comResult = m_comSession;
    920             m_comSession.UnlockMachine();
    921             return CProgress();
    922         }
    923 
    924         /* Pause VM first: */
    925         comConsole.Pause();
    926         if (!comConsole.isOk())
    927         {
    928             comResult = comConsole;
    929             m_comSession.UnlockMachine();
    930             return CProgress();
    931         }
    932     }
    933 
    934     /* Initialize progress-wrapper: */
    935     CProgress comProgress = comMachine.SaveState();
    936     /* Store COM result: */
    937     comResult = comMachine;
    938     /* Return progress-wrapper: */
    939     return comProgress;
    940 }
    941 
    942 void UINotificationProgressMachineSaveState::sltHandleProgressFinished()
    943 {
    944     /* Unlock session finally: */
    945     m_comSession.UnlockMachine();
    946968}
    947969
  • trunk/src/VBox/Frontends/VirtualBox/src/notificationcenter/UINotificationObjects.h

    r90795 r90855  
    526526
    527527    /** Constructs machine save-state notification-progress.
    528       * @param  uId  Brings the machine id. */
    529     UINotificationProgressMachineSaveState(const QUuid &uId);
    530 
    531 protected:
    532 
    533     /** Returns object name. */
    534     virtual QString name() const /* override final */;
    535     /** Returns object details. */
    536     virtual QString details() const /* override final */;
    537     /** Creates and returns started progress-wrapper. */
    538     virtual CProgress createProgress(COMResult &comResult) /* override final */;
    539 
    540 private slots:
    541 
    542     /** Handles signal about progress being finished. */
    543     void sltHandleProgressFinished();
    544 
    545 private:
    546 
    547     /** Holds the machine id. */
    548     QUuid     m_uId;
     528      * @param  comMachine  Brings the machine being saved. */
     529    UINotificationProgressMachineSaveState(const CMachine &comMachine);
     530
     531protected:
     532
     533    /** Returns object name. */
     534    virtual QString name() const /* override final */;
     535    /** Returns object details. */
     536    virtual QString details() const /* override final */;
     537    /** Creates and returns started progress-wrapper. */
     538    virtual CProgress createProgress(COMResult &comResult) /* override final */;
     539
     540private slots:
     541
     542    /** Handles signal about progress being finished. */
     543    void sltHandleProgressFinished();
     544
     545private:
     546
     547    /** Holds the machine being saved. */
     548    CMachine  m_comMachine;
    549549    /** Holds the session being opened. */
    550550    CSession  m_comSession;
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