UISession.h revision 68436b7f7bc35d8d020343b68ff117c3decdeacd
6535N/A/** @file
6535N/A * VBox Qt GUI - UISession class declaration.
6535N/A */
6535N/A
6535N/A/*
6535N/A * Copyright (C) 2010-2013 Oracle Corporation
6535N/A *
6535N/A * This file is part of VirtualBox Open Source Edition (OSE), as
6535N/A * available from http://www.virtualbox.org. This file is free software;
6535N/A * you can redistribute it and/or modify it under the terms of the GNU
6535N/A * General Public License (GPL) as published by the Free Software
6535N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
6535N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
6535N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
6535N/A */
6535N/A
6535N/A#ifndef ___UISession_h___
6535N/A#define ___UISession_h___
6535N/A
6535N/A/* Qt includes: */
6535N/A#include <QObject>
6535N/A#include <QCursor>
6535N/A#include <QEvent>
6535N/A#include <QMap>
6535N/A
6535N/A/* GUI includes: */
6535N/A#include "UIExtraDataDefs.h"
6535N/A
6535N/A/* COM includes: */
6535N/A#include "COMEnums.h"
6535N/A#include "CSession.h"
6535N/A
6535N/A/* Forward declarations: */
6535N/Aclass QMenu;
6535N/Aclass UIFrameBuffer;
6535N/Aclass UIMachine;
6535N/Aclass UIMachineLogic;
6535N/Aclass UIActionPool;
6535N/Aclass CUSBDevice;
6535N/Aclass CNetworkAdapter;
6535N/Aclass CMediumAttachment;
6535N/A#ifdef Q_WS_MAC
6535N/Aclass QMenuBar;
6535N/A#else /* !Q_WS_MAC */
6535N/Aclass QIcon;
6535N/A#endif /* !Q_WS_MAC */
6535N/A
6535N/A/* CConsole callback event types: */
6535N/Aenum UIConsoleEventType
6535N/A{
6535N/A UIConsoleEventType_MousePointerShapeChange = QEvent::User + 1,
6535N/A UIConsoleEventType_MouseCapabilityChange,
6535N/A UIConsoleEventType_KeyboardLedsChange,
6535N/A UIConsoleEventType_StateChange,
6535N/A UIConsoleEventType_AdditionsStateChange,
6535N/A UIConsoleEventType_NetworkAdapterChange,
6535N/A /* Not used: UIConsoleEventType_SerialPortChange, */
6535N/A /* Not used: UIConsoleEventType_ParallelPortChange, */
6535N/A /* Not used: UIConsoleEventType_StorageControllerChange, */
6535N/A UIConsoleEventType_MediumChange,
6535N/A /* Not used: UIConsoleEventType_CPUChange, */
6535N/A UIConsoleEventType_VRDEServerChange,
6535N/A UIConsoleEventType_VRDEServerInfoChange,
6535N/A UIConsoleEventType_USBControllerChange,
6535N/A UIConsoleEventType_USBDeviceStateChange,
6535N/A UIConsoleEventType_SharedFolderChange,
6535N/A UIConsoleEventType_RuntimeError,
6535N/A UIConsoleEventType_CanShowWindow,
6535N/A UIConsoleEventType_ShowWindow,
6535N/A UIConsoleEventType_MAX
6535N/A};
6535N/A
6535N/Aclass UISession : public QObject
6535N/A{
6535N/A Q_OBJECT;
6535N/A
6535N/Apublic:
6535N/A
6535N/A /** Factory constructor. */
6535N/A static bool create(UISession *&pSession, UIMachine *pMachine);
6535N/A /** Factory destructor. */
6535N/A static void destroy(UISession *&pSession);
6535N/A
6535N/A /* API: Runtime UI stuff: */
6535N/A void powerUp();
6535N/A bool saveState();
6535N/A bool shutdown();
6535N/A bool powerOff(bool fIncludingDiscard, bool &fServerCrashed);
6535N/A void closeRuntimeUI();
6535N/A
6535N/A /* Common getters: */
6535N/A CSession& session() { return m_session; }
6535N/A UIActionPool* actionPool() const { return m_pActionPool; }
6535N/A KMachineState machineStatePrevious() const { return m_machineStatePrevious; }
6535N/A KMachineState machineState() const { return m_machineState; }
6535N/A UIMachineLogic* machineLogic() const;
6535N/A QWidget* mainMachineWindow() const;
6535N/A QCursor cursor() const { return m_cursor; }
6535N/A
6535N/A#ifndef Q_WS_MAC
6535N/A /** @name Branding stuff.
6535N/A ** @{ */
6535N/A /** Returns redefined machine-window icon. */
6535N/A QIcon* machineWindowIcon() const { return m_pMachineWindowIcon; }
6535N/A /** Returns redefined machine-window name postfix. */
6535N/A QString machineWindowNamePostfix() const { return m_strMachineWindowNamePostfix; }
6535N/A /** @} */
6535N/A#endif /* !Q_WS_MAC */
6535N/A
6535N/A /** @name Runtime workflow stuff.
6535N/A ** @{ */
6535N/A /** Returns the mouse-capture policy. */
6535N/A MouseCapturePolicy mouseCapturePolicy() const { return m_mouseCapturePolicy; }
6535N/A /** Returns Guru Meditation handler type. */
6535N/A GuruMeditationHandlerType guruMeditationHandlerType() const { return m_guruMeditationHandlerType; }
6535N/A /** Returns HiDPI optimization type. */
6535N/A HiDPIOptimizationType hiDPIOptimizationType() const { return m_hiDPIOptimizationType; }
6535N/A /** @} */
6535N/A
6535N/A /** @name Host-screen configuration variables.
6535N/A ** @{ */
6535N/A /** Returns the list of host-screen geometries we currently have. */
6535N/A QList<QRect> hostScreens() const { return m_hostScreens; }
6535N/A /** @} */
6535N/A
6535N/A /** @name Application Close configuration stuff.
6535N/A * @{ */
6535N/A /** Returns default close action. */
6535N/A MachineCloseAction defaultCloseAction() const { return m_defaultCloseAction; }
6535N/A /** Returns merged restricted close actions. */
6535N/A MachineCloseAction restrictedCloseActions() const { return m_restrictedCloseActions; }
6535N/A /** Returns whether all the close actions are restricted. */
6535N/A bool isAllCloseActionsRestricted() const { return m_fAllCloseActionsRestricted; }
6535N/A /** @} */
6535N/A
6535N/A /** Returns whether visual @a state is allowed. */
6535N/A bool isVisualStateAllowed(UIVisualStateType state) const;
6535N/A /** Requests visual-state change. */
6535N/A void changeVisualState(UIVisualStateType visualStateType);
6535N/A /** Requests visual-state to be entered when possible. */
6535N/A void setRequestedVisualState(UIVisualStateType visualStateType) { m_requestedVisualStateType = visualStateType; }
6535N/A /** Returns requested visual-state to be entered when possible. */
6535N/A UIVisualStateType requestedVisualState() const { return m_requestedVisualStateType; }
6535N/A
6535N/A bool isSaved() const { return machineState() == KMachineState_Saved; }
6535N/A bool isTurnedOff() const { return machineState() == KMachineState_PoweredOff ||
6535N/A machineState() == KMachineState_Saved ||
6535N/A machineState() == KMachineState_Teleported ||
6535N/A machineState() == KMachineState_Aborted; }
6535N/A bool isPaused() const { return machineState() == KMachineState_Paused ||
6535N/A machineState() == KMachineState_TeleportingPausedVM; }
6535N/A bool isRunning() const { return machineState() == KMachineState_Running ||
6535N/A machineState() == KMachineState_Teleporting ||
6535N/A machineState() == KMachineState_LiveSnapshotting; }
6535N/A bool isStuck() const { return machineState() == KMachineState_Stuck; }
6535N/A bool wasPaused() const { return machineStatePrevious() == KMachineState_Paused ||
6535N/A machineStatePrevious() == KMachineState_TeleportingPausedVM; }
bool isStarted() const { return m_fIsStarted; }
bool isFirstTimeStarted() const { return m_fIsFirstTimeStarted; }
bool isGuestResizeIgnored() const { return m_fIsGuestResizeIgnored; }
bool isAutoCaptureDisabled() const { return m_fIsAutoCaptureDisabled; }
/* Guest additions state getters: */
bool isGuestAdditionsActive() const { return (m_ulGuestAdditionsRunLevel > AdditionsRunLevelType_None); }
bool isGuestSupportsGraphics() const { return isGuestAdditionsActive() && m_fIsGuestSupportsGraphics; }
bool isGuestSupportsSeamless() const { return isGuestSupportsGraphics() && m_fIsGuestSupportsSeamless; }
/* Keyboard getters: */
/** Returns keyboard-state. */
int keyboardState() const { return m_iKeyboardState; }
bool isNumLock() const { return m_fNumLock; }
bool isCapsLock() const { return m_fCapsLock; }
bool isScrollLock() const { return m_fScrollLock; }
uint numLockAdaptionCnt() const { return m_uNumLockAdaptionCnt; }
uint capsLockAdaptionCnt() const { return m_uCapsLockAdaptionCnt; }
/* Mouse getters: */
/** Returns mouse-state. */
int mouseState() const { return m_iMouseState; }
bool isMouseSupportsAbsolute() const { return m_fIsMouseSupportsAbsolute; }
bool isMouseSupportsRelative() const { return m_fIsMouseSupportsRelative; }
bool isMouseSupportsMultiTouch() const { return m_fIsMouseSupportsMultiTouch; }
bool isMouseHostCursorNeeded() const { return m_fIsMouseHostCursorNeeded; }
bool isMouseCaptured() const { return m_fIsMouseCaptured; }
bool isMouseIntegrated() const { return m_fIsMouseIntegrated; }
bool isValidPointerShapePresent() const { return m_fIsValidPointerShapePresent; }
bool isHidingHostPointer() const { return m_fIsHidingHostPointer; }
/* Common setters: */
bool pause() { return setPause(true); }
bool unpause() { return setPause(false); }
bool setPause(bool fOn);
void setGuestResizeIgnored(bool fIsGuestResizeIgnored) { m_fIsGuestResizeIgnored = fIsGuestResizeIgnored; }
void setAutoCaptureDisabled(bool fIsAutoCaptureDisabled) { m_fIsAutoCaptureDisabled = fIsAutoCaptureDisabled; }
void forgetPreviousMachineState() { m_machineStatePrevious = m_machineState; }
/* Keyboard setters: */
void setNumLockAdaptionCnt(uint uNumLockAdaptionCnt) { m_uNumLockAdaptionCnt = uNumLockAdaptionCnt; }
void setCapsLockAdaptionCnt(uint uCapsLockAdaptionCnt) { m_uCapsLockAdaptionCnt = uCapsLockAdaptionCnt; }
/* Mouse setters: */
void setMouseCaptured(bool fIsMouseCaptured) { m_fIsMouseCaptured = fIsMouseCaptured; }
void setMouseIntegrated(bool fIsMouseIntegrated) { m_fIsMouseIntegrated = fIsMouseIntegrated; }
/* Screen visibility status: */
bool isScreenVisible(ulong uScreenId) const;
void setScreenVisible(ulong uScreenId, bool fIsMonitorVisible);
/* Returns existing framebuffer for the given screen-number;
* Returns 0 (asserts) if screen-number attribute is out of bounds: */
UIFrameBuffer* frameBuffer(ulong uScreenId) const;
/* Sets framebuffer for the given screen-number;
* Ignores (asserts) if screen-number attribute is out of bounds: */
void setFrameBuffer(ulong uScreenId, UIFrameBuffer* pFrameBuffer);
/** Returns existing frame-buffer vector. */
const QVector<ComObjPtr<UIFrameBuffer> >& frameBuffers() const { return m_frameBufferVector; }
/* Temporary API: */
void updateStatusVRDE() { sltVRDEChange(); }
void updateStatusVideoCapture() { sltVideoCaptureChange(); }
signals:
/* Notifier: Close Runtime UI stuff: */
void sigCloseRuntimeUI();
/** Notifies about frame-buffer resize. */
void sigFrameBufferResize();
/* Console callback signals: */
/** Notifies listeners about keyboard state-change. */
void sigKeyboardStateChange(int iState);
/** Notifies listeners about mouse state-change. */
void sigMouseStateChange(int iState);
void sigMousePointerShapeChange();
void sigMouseCapabilityChange();
void sigKeyboardLedsChange();
void sigMachineStateChange();
void sigAdditionsStateChange();
void sigNetworkAdapterChange(const CNetworkAdapter &networkAdapter);
void sigMediumChange(const CMediumAttachment &mediumAttachment);
void sigVRDEChange();
void sigVideoCaptureChange();
void sigUSBControllerChange();
void sigUSBDeviceStateChange(const CUSBDevice &device, bool bIsAttached, const CVirtualBoxErrorInfo &error);
void sigSharedFolderChange();
void sigRuntimeError(bool bIsFatal, const QString &strErrorId, const QString &strMessage);
#ifdef RT_OS_DARWIN
void sigShowWindows();
#endif /* RT_OS_DARWIN */
void sigCPUExecutionCapChange();
void sigGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo);
/** Notifies about host-screen count change. */
void sigHostScreenCountChange();
/** Notifies about host-screen geometry change. */
void sigHostScreenGeometryChange();
/** Notifies about host-screen available-area change. */
void sigHostScreenAvailableAreaChange();
/* Session signals: */
void sigStarted();
public slots:
void sltInstallGuestAdditionsFrom(const QString &strSource);
/** Defines @a iKeyboardState. */
void setKeyboardState(int iKeyboardState) { m_iKeyboardState = iKeyboardState; emit sigKeyboardStateChange(m_iKeyboardState); }
/** Defines @a iMouseState. */
void setMouseState(int iMouseState) { m_iMouseState = iMouseState; emit sigMouseStateChange(m_iMouseState); }
private slots:
/** Marks machine started. */
void sltMarkStarted() { m_fIsStarted = true; }
/* Handler: Close Runtime UI stuff: */
void sltCloseRuntimeUI();
#ifdef RT_OS_DARWIN
/** Mac OS X: Handles menu-bar configuration-change. */
void sltHandleMenuBarConfigurationChange();
#endif /* RT_OS_DARWIN */
/* Console events slots */
void sltMousePointerShapeChange(bool fVisible, bool fAlpha, QPoint hotCorner, QSize size, QVector<uint8_t> shape);
void sltMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative, bool fSupportsMultiTouch, bool fNeedsHostCursor);
void sltKeyboardLedsChangeEvent(bool fNumLock, bool fCapsLock, bool fScrollLock);
void sltStateChange(KMachineState state);
void sltAdditionsChange();
void sltVRDEChange();
void sltVideoCaptureChange();
void sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo);
/* Handlers: Display reconfiguration stuff: */
#ifdef RT_OS_DARWIN
void sltHandleHostDisplayAboutToChange();
void sltCheckIfHostDisplayChanged();
#endif /* RT_OS_DARWIN */
/** Handles host-screen count change. */
void sltHandleHostScreenCountChange();
/** Handles host-screen geometry change. */
void sltHandleHostScreenGeometryChange();
/** Handles host-screen available-area change. */
void sltHandleHostScreenAvailableAreaChange();
private:
/** Constructor. */
UISession(UIMachine *pMachine);
/** Destructor. */
~UISession();
/* Private getters: */
UIMachine* uimachine() const { return m_pMachine; }
/* Prepare helpers: */
bool prepare();
bool prepareSession();
void prepareActions();
void prepareConnections();
void prepareConsoleEventHandlers();
void prepareScreens();
void prepareFramebuffers();
void loadSessionSettings();
/* Cleanup helpers: */
void saveSessionSettings();
void cleanupFramebuffers();
//void cleanupScreens() {}
void cleanupConsoleEventHandlers();
void cleanupConnections();
void cleanupActions();
void cleanupSession();
void cleanup();
#ifdef Q_WS_MAC
/** Mac OS X: Updates menu-bar content. */
void updateMenu();
#endif /* Q_WS_MAC */
/* Common helpers: */
WId winId() const;
void setPointerShape(const uchar *pShapeData, bool fHasAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight);
bool preparePowerUp();
int countOfVisibleWindows();
/** Update host-screen data. */
void updateHostScreenData();
/* Private variables: */
UIMachine *m_pMachine;
/** Holds the session instance. */
CSession m_session;
/** Holds the action-pool instance. */
UIActionPool *m_pActionPool;
#ifdef Q_WS_MAC
/** Holds the menu-bar instance. */
QMenuBar *m_pMenuBar;
#endif /* Q_WS_MAC */
/* Screen visibility vector: */
QVector<bool> m_monitorVisibilityVector;
/* Frame-buffers vector: */
QVector<ComObjPtr<UIFrameBuffer> > m_frameBufferVector;
/* Common variables: */
KMachineState m_machineStatePrevious;
KMachineState m_machineState;
QCursor m_cursor;
#ifndef Q_WS_MAC
/** @name Branding variables.
** @{ */
/** Holds redefined machine-window icon. */
QIcon *m_pMachineWindowIcon;
/** Holds redefined machine-window name postfix. */
QString m_strMachineWindowNamePostfix;
/** @} */
#endif /* !Q_WS_MAC */
/** @name Runtime workflow variables.
** @{ */
/** Holds the mouse-capture policy. */
MouseCapturePolicy m_mouseCapturePolicy;
/** Holds Guru Meditation handler type. */
GuruMeditationHandlerType m_guruMeditationHandlerType;
/** Holds HiDPI optimization type. */
HiDPIOptimizationType m_hiDPIOptimizationType;
/** @} */
/** @name Visual-state configuration variables.
** @{ */
/** Determines which visual-state should be entered when possible. */
UIVisualStateType m_requestedVisualStateType;
/** @} */
#if defined(Q_WS_WIN)
HCURSOR m_alphaCursor;
#endif
/** @name Host-screen configuration variables.
* @{ */
/** Holds the list of host-screen geometries we currently have. */
QList<QRect> m_hostScreens;
#ifdef Q_WS_MAC
/** Mac OS X: Watchdog timer looking for display reconfiguration. */
QTimer *m_pWatchdogDisplayChange;
#endif /* Q_WS_MAC */
/** @} */
/** @name Application Close configuration variables.
* @{ */
/** Default close action. */
MachineCloseAction m_defaultCloseAction;
/** Merged restricted close actions. */
MachineCloseAction m_restrictedCloseActions;
/** Determines whether all the close actions are restricted. */
bool m_fAllCloseActionsRestricted;
/** @} */
/* Common flags: */
bool m_fIsStarted : 1;
bool m_fIsFirstTimeStarted : 1;
bool m_fIsGuestResizeIgnored : 1;
bool m_fIsAutoCaptureDisabled : 1;
/* Guest additions flags: */
ULONG m_ulGuestAdditionsRunLevel;
bool m_fIsGuestSupportsGraphics : 1;
bool m_fIsGuestSupportsSeamless : 1;
/* Keyboard flags: */
/** Holds the keyboard-state. */
int m_iKeyboardState;
bool m_fNumLock : 1;
bool m_fCapsLock : 1;
bool m_fScrollLock : 1;
uint m_uNumLockAdaptionCnt;
uint m_uCapsLockAdaptionCnt;
/* Mouse flags: */
/** Holds the mouse-state. */
int m_iMouseState;
bool m_fIsMouseSupportsAbsolute : 1;
bool m_fIsMouseSupportsRelative : 1;
bool m_fIsMouseSupportsMultiTouch: 1;
bool m_fIsMouseHostCursorNeeded : 1;
bool m_fIsMouseCaptured : 1;
bool m_fIsMouseIntegrated : 1;
bool m_fIsValidPointerShapePresent : 1;
bool m_fIsHidingHostPointer : 1;
/* Friend classes: */
friend class UIConsoleEventHandler;
};
#endif /* !___UISession_h___ */