VirtualBox

Changeset 64160 in vbox for trunk/src


Ignore:
Timestamp:
Oct 6, 2016 12:03:52 PM (8 years ago)
Author:
vboxsync
Message:

VBoxFrontends: fix for bugref:8161: added shutdown events handling to VirtualBox UI

Location:
trunk/src/VBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r63694 r64160  
    147147#include <QSettings>
    148148#include <QStyleOptionSpinBox>
     149#include <QSessionManager>
    149150
    150151/* Other VBox includes: */
     
    38993900    /* Make sure QApplication cleanup us on exit: */
    39003901    connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanup()));
     3902    /* Make sure we handle host OS session shutdown as well: */
     3903    connect(qApp, SIGNAL(commitDataRequest(QSessionManager &)),
     3904            this, SLOT(sltHandleCommitDataRequest(QSessionManager &)));
    39013905
    39023906#ifdef VBOX_WS_MAC
     
    44134417}
    44144418
     4419#ifdef VBOX_WS_WIN
     4420/* static */
     4421BOOL VBoxGlobal::ShutdownBlockReasonCreateAPI(HWND hWnd, LPCWSTR pwszReason)
     4422{
     4423    BOOL fResult = FALSE;
     4424    typedef BOOL(WINAPI *PFNSHUTDOWNBLOCKREASONCREATE)(HWND hWnd, LPCWSTR pwszReason);
     4425
     4426    PFNSHUTDOWNBLOCKREASONCREATE pfn = (PFNSHUTDOWNBLOCKREASONCREATE)GetProcAddress(
     4427        GetModuleHandle(L"User32.dll"), "ShutdownBlockReasonCreate");
     4428    _ASSERTE(pfn);
     4429    if (pfn)
     4430        fResult = pfn(hWnd, pwszReason);
     4431    return fResult;
     4432}
     4433#endif
     4434
     4435void VBoxGlobal::sltHandleCommitDataRequest(QSessionManager &manager)
     4436{
     4437    LogRel(("GUI: VBoxGlobal::sltHandleCommitDataRequest: Emergency shutdown initiated\n"));
     4438
     4439    /* For VM process: */
     4440    if (vboxGlobal().isVMConsoleProcess())
     4441    {
     4442        /* Temporary override the default close action to 'SaveState' if necessary: */
     4443        if (gpMachine->uisession()->defaultCloseAction() == MachineCloseAction_Invalid)
     4444            gpMachine->uisession()->setDefaultCloseAction(MachineCloseAction_SaveState);
     4445    }
     4446
     4447    /* Ask session manager to postpone shutdown until we done: */
     4448    manager.cancel();
     4449
     4450#ifdef VBOX_WS_WIN
     4451    // WORKAROUND:
     4452    // In theory that's Qt5 who should allow us to provide postponing reason as well,
     4453    // but that functionality seems missed in Windows platform plugin, so we are making that ourselves.
     4454    // That also implies that since we had postponed a shutdown process, host will send us WM_QUIT to
     4455    // allow to properly do an application cleanup first. That signal will cause QApplication to quit().
     4456    ShutdownBlockReasonCreateAPI((HWND)windowManager().mainWindowShown()->winId(), L"Shutdown in progress...");
     4457#endif
     4458}
     4459
    44154460void VBoxGlobal::sltHandleVBoxSVCAvailabilityChange(bool fAvailable)
    44164461{
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r63054 r64160  
    469469    void cleanup();
    470470
     471    /** Handles @a manager request for emergency session shutdown. */
     472    void sltHandleCommitDataRequest(QSessionManager &manager);
     473
    471474    /** Shows UI. */
    472475    void showUI();
     
    487490    /** Re-initializes COM wrappers and containers. */
    488491    void comWrappersReinit();
     492
     493#ifdef VBOX_WS_WIN
     494    /** Wraps WinAPI ShutdownBlockReasonCreate function.
     495      * @remark  This function defined starting from Vista only. */
     496    static BOOL ShutdownBlockReasonCreateAPI(HWND hWnd, LPCWSTR pwszReason);
     497#endif
    489498
    490499#ifdef VBOX_WITH_DEBUGGER_GUI
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r62493 r64160  
    146146    /** @name Application Close configuration stuff.
    147147     * @{ */
     148    /** Defines @a defaultCloseAction. */
     149    void setDefaultCloseAction(MachineCloseAction defaultCloseAction) { m_defaultCloseAction = defaultCloseAction; }
    148150    /** Returns default close action. */
    149151    MachineCloseAction defaultCloseAction() const { return m_defaultCloseAction; }
  • trunk/src/VBox/Main/src-server/win/svcmain.cpp

    r63549 r64160  
    155155BOOL ShutdownBlockReasonCreateAPI(HWND hWnd,LPCWSTR pwszReason)
    156156{
    157     BOOL result = FALSE;
     157    BOOL fResult = FALSE;
    158158    typedef BOOL(WINAPI *PFNSHUTDOWNBLOCKREASONCREATE)(HWND hWnd, LPCWSTR pwszReason);
    159159
     
    162162    _ASSERTE(pfn);
    163163    if (pfn)
    164         result = pfn(hWnd, pwszReason);
    165     return result;
     164        fResult = pfn(hWnd, pwszReason);
     165    return fResult;
    166166}
    167167
     
    172172BOOL ShutdownBlockReasonDestroyAPI(HWND hWnd)
    173173{
    174     BOOL result = FALSE;
     174    BOOL fResult = FALSE;
    175175    typedef BOOL(WINAPI *PFNSHUTDOWNBLOCKREASONDESTROY)(HWND hWnd);
    176176
     
    179179    _ASSERTE(pfn);
    180180    if (pfn)
    181         result = pfn(hWnd);
    182     return result;
     181        fResult = pfn(hWnd);
     182    return fResult;
    183183}
    184184
     
    198198            /* decrease a latency of MonitorShutdown loop */
    199199            ASMAtomicXchgU32(&dwTimeOut, 100);
    200             Log(("VBoxSVCWinMain: VBoxSvc has active connections. bActivity = %d. Loc count = %d\n",
     200            Log(("VBoxSVCWinMain: WM_QUERYENDSESSION: VBoxSvc has active connections. bActivity = %d. Loc count = %d\n",
    201201                _Module.bActivity, _Module.GetLockCount()));
    202202        }
    203         Log(("VBoxSVCWinMain: WM_QUERYENDSESSION msg: %d rc= %d\n", msg, rc));
    204     } break;
     203     } break;
    205204    case WM_ENDSESSION:
    206205    {
     
    211210            Log(("VBoxSVCWinMain: user canceled system shutdown.\n"));
    212211        }
    213         Log(("VBoxSVCWinMain: WM_ENDSESSION msg: %d. wParam: %d. lParam: %d\n", msg, wParam, lParam));
    214212    } break;
    215213    case WM_DESTROY:
    216214    {
    217         Log(("VBoxSVCWinMain: WM_DESTROY \n"));
    218215        ShutdownBlockReasonDestroyAPI(hwnd);
    219216        PostQuitMessage(0);
     
    222219    default:
    223220    {
    224         Log(("VBoxSVCWinMain: msg %p\n", msg));
    225221        rc = DefWindowProc(hwnd, msg, wParam, lParam);
    226222    }
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