VirtualBox

Changeset 98617 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Feb 17, 2023 11:44:48 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155909
Message:

FE/Qt: bugref:10322: Runtime UI: Reworking CConsole wrapper usage step-by-step; This one is about save state, shutdown and power off stuff.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r98607 r98617  
    661661void UIMachine::saveState()
    662662{
    663     /* Prepare VM to be saved: */
    664     if (!uisession()->prepareToBeSaved())
    665         return;
    666 
    667     /* Enable 'manual-override',
    668      * preventing automatic Runtime UI closing: */
    669     setManualOverrideMode(true);
    670 
    671     /* Now, do the magic: */
    672     LogRel(("GUI: Saving VM state..\n"));
    673     UINotificationProgressMachineSaveState *pNotification =
    674         new UINotificationProgressMachineSaveState(uisession()->machine());
    675     connect(pNotification, &UINotificationProgressMachineSaveState::sigMachineStateSaved,
    676             this, &UIMachine::sltHandleMachineStateSaved);
    677     gpNotificationCenter->append(pNotification);
     663    uisession()->saveState();
    678664}
    679665
    680666void UIMachine::shutdown()
    681667{
    682     /* Prepare VM to be shutdowned: */
    683     if (!uisession()->prepareToBeShutdowned())
    684         return;
    685 
    686     /* Now, do the magic: */
    687     LogRel(("GUI: Sending ACPI shutdown signal..\n"));
    688     CConsole comConsole = uisession()->console();
    689     comConsole.PowerButton();
    690     if (!comConsole.isOk())
    691         UINotificationMessage::cannotACPIShutdownMachine(uisession()->console());
     668    uisession()->shutdown();
    692669}
    693670
    694671void UIMachine::powerOff(bool fIncludingDiscard)
    695672{
    696     /* Enable 'manual-override',
    697      * preventing automatic Runtime UI closing: */
    698     setManualOverrideMode(true);
    699 
    700     /* Now, do the magic: */
    701     LogRel(("GUI: Powering VM off..\n"));
    702     UINotificationProgressMachinePowerOff *pNotification =
    703         new UINotificationProgressMachinePowerOff(uisession()->machine(),
    704                                                   uisession()->console(),
    705                                                   fIncludingDiscard);
    706     connect(pNotification, &UINotificationProgressMachinePowerOff::sigMachinePoweredOff,
    707             this, &UIMachine::sltHandleMachinePoweredOff);
    708     gpNotificationCenter->append(pNotification);
     673    uisession()->powerOff(fIncludingDiscard);
    709674}
    710675
     
    10451010        emit sigCursorPositionChange();
    10461011    }
    1047 }
    1048 
    1049 void UIMachine::sltHandleMachineStateSaved(bool fSuccess)
    1050 {
    1051     /* Let user try again if saving failed: */
    1052     if (!fSuccess)
    1053     {
    1054         /* Disable 'manual-override' finally: */
    1055         setManualOverrideMode(false);
    1056     }
    1057     /* Close Runtime UI otherwise: */
    1058     else
    1059         closeRuntimeUI();
    1060 }
    1061 
    1062 void UIMachine::sltHandleMachinePoweredOff(bool fSuccess, bool fIncludingDiscard)
    1063 {
    1064     /* Let user try again if power off failed: */
    1065     if (!fSuccess)
    1066     {
    1067         /* Disable 'manual-override' finally: */
    1068         setManualOverrideMode(false);
    1069     }
    1070     /* Check for other tasks otherwise: */
    1071     else
    1072     {
    1073         if (fIncludingDiscard)
    1074         {
    1075             /* Now, do more magic! */
    1076             UINotificationProgressSnapshotRestore *pNotification =
    1077                 new UINotificationProgressSnapshotRestore(uiCommon().managedVMUuid());
    1078             connect(pNotification, &UINotificationProgressSnapshotRestore::sigSnapshotRestored,
    1079                     this, &UIMachine::sltHandleSnapshotRestored);
    1080             gpNotificationCenter->append(pNotification);
    1081         }
    1082         else
    1083             closeRuntimeUI();
    1084     }
    1085 }
    1086 
    1087 void UIMachine::sltHandleSnapshotRestored(bool)
    1088 {
    1089     /* Close Runtime UI independent of snapshot restoring state: */
    1090     closeRuntimeUI();
    10911012}
    10921013
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h

    r98607 r98617  
    613613    /** @} */
    614614
    615     /** @name Close stuff.
    616      ** @{ */
    617         /** Handles signal about machine state saved.
    618           * @param  fSuccess  Brings whether state was saved successfully. */
    619         void sltHandleMachineStateSaved(bool fSuccess);
    620         /** Handles signal about machine powered off.
    621           * @param  fSuccess           Brings whether machine was powered off successfully.
    622           * @param  fIncludingDiscard  Brings whether machine state should be discarded. */
    623         void sltHandleMachinePoweredOff(bool fSuccess, bool fIncludingDiscard);
    624         /** Handles signal about snapshot restored.
    625           * @param  fSuccess  Brings whether machine was powered off successfully. */
    626         void sltHandleSnapshotRestored(bool fSuccess);
    627     /** @} */
    628 
    629615private:
    630616
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r98607 r98617  
    804804}
    805805
    806 bool UISession::prepareToBeSaved()
    807 {
    808     return    isPaused()
    809            || (isRunning() && pause());
    810 }
    811 
    812 bool UISession::prepareToBeShutdowned()
    813 {
     806void UISession::saveState()
     807{
     808    if (   isPaused()
     809        || (isRunning() && pause()))
     810    {
     811        /* Enable 'manual-override',
     812         * preventing automatic Runtime UI closing: */
     813        uimachine()->setManualOverrideMode(true);
     814
     815        /* Now, do the magic: */
     816        LogRel(("GUI: Saving VM state..\n"));
     817        UINotificationProgressMachineSaveState *pNotification =
     818            new UINotificationProgressMachineSaveState(machine());
     819        connect(pNotification, &UINotificationProgressMachineSaveState::sigMachineStateSaved,
     820                this, &UISession::sltHandleMachineStateSaved);
     821        gpNotificationCenter->append(pNotification);
     822    }
     823}
     824
     825void UISession::shutdown()
     826{
     827    /* Check whether guest is in proper mode: */
    814828    bool fValidMode = false;
    815829    acquireWhetherGuestEnteredACPIMode(fValidMode);
    816830    if (!fValidMode)
    817831        UINotificationMessage::cannotSendACPIToMachine();
    818     return fValidMode;
     832    else
     833    {
     834        /* Now, do the magic: */
     835        LogRel(("GUI: Sending ACPI shutdown signal..\n"));
     836        CConsole comConsole = console();
     837        comConsole.PowerButton();
     838        if (!comConsole.isOk())
     839            UINotificationMessage::cannotACPIShutdownMachine(comConsole);
     840    }
     841}
     842
     843void UISession::powerOff(bool fIncludingDiscard)
     844{
     845    /* Enable 'manual-override',
     846     * preventing automatic Runtime UI closing: */
     847    uimachine()->setManualOverrideMode(true);
     848
     849    /* Now, do the magic: */
     850    LogRel(("GUI: Powering VM off..\n"));
     851    UINotificationProgressMachinePowerOff *pNotification =
     852        new UINotificationProgressMachinePowerOff(machine(),
     853                                                  console(),
     854                                                  fIncludingDiscard);
     855    connect(pNotification, &UINotificationProgressMachinePowerOff::sigMachinePoweredOff,
     856            this, &UISession::sltHandleMachinePoweredOff);
     857    gpNotificationCenter->append(pNotification);
    819858}
    820859
     
    889928    /* Notify listeners about GA state change event came: */
    890929    emit sigAdditionsStateChange();
     930}
     931
     932void UISession::sltHandleMachineStateSaved(bool fSuccess)
     933{
     934    /* Let user try again if saving failed: */
     935    if (!fSuccess)
     936    {
     937        /* Disable 'manual-override' finally: */
     938        uimachine()->setManualOverrideMode(false);
     939    }
     940    /* Close Runtime UI otherwise: */
     941    else
     942        uimachine()->closeRuntimeUI();
     943}
     944
     945void UISession::sltHandleMachinePoweredOff(bool fSuccess, bool fIncludingDiscard)
     946{
     947    /* Let user try again if power off failed: */
     948    if (!fSuccess)
     949    {
     950        /* Disable 'manual-override' finally: */
     951        uimachine()->setManualOverrideMode(false);
     952    }
     953    /* Check for other tasks otherwise: */
     954    else
     955    {
     956        if (fIncludingDiscard)
     957        {
     958            /* Now, do more magic! */
     959            UINotificationProgressSnapshotRestore *pNotification =
     960                new UINotificationProgressSnapshotRestore(uiCommon().managedVMUuid());
     961            connect(pNotification, &UINotificationProgressSnapshotRestore::sigSnapshotRestored,
     962                    this, &UISession::sltHandleSnapshotRestored);
     963            gpNotificationCenter->append(pNotification);
     964        }
     965        else
     966            uimachine()->closeRuntimeUI();
     967    }
     968}
     969
     970void UISession::sltHandleSnapshotRestored(bool)
     971{
     972    /* Close Runtime UI independent of snapshot restoring state: */
     973    uimachine()->closeRuntimeUI();
    891974}
    892975
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r98607 r98617  
    395395        bool acquireWhetherGuestEnteredACPIMode(bool &fEntered);
    396396
    397         /** Prepares VM to be saved. */
    398         bool prepareToBeSaved();
    399         /** Returns whether VM can be shutdowned. */
    400         bool prepareToBeShutdowned();
     397        /** Saves VM state, then closes Runtime UI. */
     398        void saveState();
     399        /** Calls for guest shutdown to close Runtime UI. */
     400        void shutdown();
     401        /** Powers VM off, then closes Runtime UI. */
     402        void powerOff(bool fIncludingDiscard);
    401403    /** @} */
    402404
     
    431433        /** Handles event about guest additions change. */
    432434        void sltAdditionsChange();
     435    /** @} */
     436
     437    /** @name Close stuff.
     438     ** @{ */
     439        /** Handles signal about machine state saved.
     440          * @param  fSuccess  Brings whether state was saved successfully. */
     441        void sltHandleMachineStateSaved(bool fSuccess);
     442        /** Handles signal about machine powered off.
     443          * @param  fSuccess           Brings whether machine was powered off successfully.
     444          * @param  fIncludingDiscard  Brings whether machine state should be discarded. */
     445        void sltHandleMachinePoweredOff(bool fSuccess, bool fIncludingDiscard);
     446        /** Handles signal about snapshot restored.
     447          * @param  fSuccess  Brings whether machine was powered off successfully. */
     448        void sltHandleSnapshotRestored(bool fSuccess);
    433449    /** @} */
    434450
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette