UISession.h revision 4feb9880954f5fcb0c98feb110721798baccf992
1N/A/** @file
1N/A *
1N/A * VBox frontends: Qt GUI ("VirtualBox"):
1N/A * UISession class declaration
1N/A */
1N/A
1N/A/*
1N/A * Copyright (C) 2010-2012 Oracle Corporation
1N/A *
1N/A * This file is part of VirtualBox Open Source Edition (OSE), as
1N/A * available from http://www.virtualbox.org. This file is free software;
1N/A * you can redistribute it and/or modify it under the terms of the GNU
1N/A * General Public License (GPL) as published by the Free Software
1N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
1N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1N/A */
1N/A
1N/A#ifndef ___UIConsole_h___
1N/A#define ___UIConsole_h___
1N/A
1N/A/* Qt includes: */
1N/A#include <QObject>
1N/A#include <QCursor>
1N/A#include <QEvent>
1N/A
1N/A/* GUI includes: */
1N/A#include "UIMachineDefs.h"
1N/A
1N/A/* COM includes: */
1N/A#include "COMEnums.h"
1N/A
1N/A/* Forward declarations: */
1N/Aclass QMenu;
1N/Aclass QMenuBar;
1N/A#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
1N/A# ifdef Q_WS_MAC
1N/Astruct __siginfo;
1N/Atypedef struct __siginfo siginfo_t;
1N/A# else /* Q_WS_MAC */
1N/Astruct siginfo;
1N/Atypedef struct siginfo siginfo_t;
1N/A# endif /* !Q_WS_MAC */
1N/A#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
1N/Aclass UIFrameBuffer;
1N/Aclass UIMachine;
1N/Aclass UIMachineLogic;
1N/Aclass UIMachineMenuBar;
1N/Aclass CSession;
1N/Aclass CUSBDevice;
1N/Aclass CNetworkAdapter;
1N/Aclass CMediumAttachment;
1N/A
1N/A/* CConsole callback event types: */
1N/Aenum UIConsoleEventType
1N/A{
1N/A UIConsoleEventType_MousePointerShapeChange = QEvent::User + 1,
1N/A UIConsoleEventType_MouseCapabilityChange,
1N/A UIConsoleEventType_KeyboardLedsChange,
1N/A UIConsoleEventType_StateChange,
1N/A UIConsoleEventType_AdditionsStateChange,
1N/A UIConsoleEventType_NetworkAdapterChange,
1N/A /* Not used: UIConsoleEventType_SerialPortChange, */
1N/A /* Not used: UIConsoleEventType_ParallelPortChange, */
1N/A /* Not used: UIConsoleEventType_StorageControllerChange, */
1N/A UIConsoleEventType_MediumChange,
1N/A /* Not used: UIConsoleEventType_CPUChange, */
1N/A UIConsoleEventType_VRDEServerChange,
1N/A UIConsoleEventType_VRDEServerInfoChange,
1N/A UIConsoleEventType_USBControllerChange,
1N/A UIConsoleEventType_USBDeviceStateChange,
1N/A UIConsoleEventType_SharedFolderChange,
1N/A UIConsoleEventType_RuntimeError,
1N/A UIConsoleEventType_CanShowWindow,
1N/A UIConsoleEventType_ShowWindow,
1N/A UIConsoleEventType_MAX
1N/A};
1N/A
1N/Aclass UISession : public QObject
1N/A{
1N/A Q_OBJECT;
1N/A
1N/Apublic:
1N/A
1N/A /* Machine uisession constructor/destructor: */
1N/A UISession(UIMachine *pMachine, CSession &session);
1N/A virtual ~UISession();
1N/A
1N/A /* API: Runtime UI stuff: */
1N/A void powerUp();
1N/A bool saveState();
1N/A bool shutdown();
1N/A bool powerOff(bool fIncludingDiscard, bool &fServerCrashed);
1N/A void closeRuntimeUI();
1N/A
1N/A /* Common getters: */
1N/A CSession& session() { return m_session; }
1N/A KMachineState machineState() const { return m_machineState; }
1N/A UIMachineLogic* machineLogic() const;
1N/A QWidget* mainMachineWindow() const;
1N/A QMenu* newMenu(UIMainMenuType fOptions = UIMainMenuType_All);
1N/A QMenuBar* newMenuBar(UIMainMenuType fOptions = UIMainMenuType_All);
1N/A QCursor cursor() const { return m_cursor; }
1N/A
bool isSaved() const { return machineState() == KMachineState_Saved; }
bool isTurnedOff() const { return machineState() == KMachineState_PoweredOff ||
machineState() == KMachineState_Saved ||
machineState() == KMachineState_Teleported ||
machineState() == KMachineState_Aborted; }
bool isPaused() const { return machineState() == KMachineState_Paused ||
machineState() == KMachineState_TeleportingPausedVM; }
bool isRunning() const { return machineState() == KMachineState_Running ||
machineState() == KMachineState_Teleporting ||
machineState() == KMachineState_LiveSnapshotting; }
bool isStuck() const { return machineState() == KMachineState_Stuck; }
bool isFirstTimeStarted() const { return m_fIsFirstTimeStarted; }
bool isIgnoreRuntimeMediumsChanging() const { return m_fIsIgnoreRuntimeMediumsChanging; }
bool isGuestResizeIgnored() const { return m_fIsGuestResizeIgnored; }
bool isSeamlessModeRequested() const { return m_fIsSeamlessModeRequested; }
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: */
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: */
bool isMouseSupportsAbsolute() const { return m_fIsMouseSupportsAbsolute; }
bool isMouseSupportsRelative() const { return m_fIsMouseSupportsRelative; }
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 setSeamlessModeRequested(bool fIsSeamlessModeRequested) { m_fIsSeamlessModeRequested = fIsSeamlessModeRequested; }
void setAutoCaptureDisabled(bool fIsAutoCaptureDisabled) { m_fIsAutoCaptureDisabled = fIsAutoCaptureDisabled; }
/* 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);
signals:
/* Notifier: Close Runtime UI stuff: */
void sigCloseRuntimeUI();
/* Console callback signals: */
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);
/* Qt callback signal: */
void sigHostScreenCountChanged(int cHostScreenCount);
/* Session signals: */
void sigMachineStarted();
public slots:
void sltInstallGuestAdditionsFrom(const QString &strSource);
private slots:
/* Handler: Close Runtime UI stuff: */
void sltCloseRuntimeUI();
/* Console events slots */
void sltMousePointerShapeChange(bool fVisible, bool fAlpha, QPoint hotCorner, QSize size, QVector<uint8_t> shape);
void sltMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative, 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);
private:
/* Private getters: */
UIMachine* uimachine() const { return m_pMachine; }
/* Prepare helpers: */
void prepareConnections();
void prepareConsoleEventHandlers();
void prepareScreens();
void prepareFramebuffers();
void prepareMenuPool();
void loadSessionSettings();
/* Cleanup helpers: */
void saveSessionSettings();
void cleanupMenuPool();
void cleanupFramebuffers();
//void cleanupScreens() {}
void cleanupConsoleEventHandlers();
//void cleanupConnections() {}
/* Update helpers: */
void updateSessionSettings();
/* Common helpers: */
WId winId() const;
void setPointerShape(const uchar *pShapeData, bool fHasAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight);
void reinitMenuPool();
bool preparePowerUp();
void adjustGuestView();
int countOfVisibleWindows();
#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
static void signalHandlerSIGUSR1(int sig, siginfo_t *pInfo, void *pSecret);
#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
/* Private variables: */
UIMachine *m_pMachine;
CSession &m_session;
UIMachineMenuBar *m_pMenuPool;
/* Screen visibility vector: */
QVector<bool> m_monitorVisibilityVector;
/* Frame-buffers vector: */
QVector<UIFrameBuffer*> m_frameBufferVector;
/* Common variables: */
KMachineState m_machineState;
QCursor m_cursor;
#if defined(Q_WS_WIN)
HCURSOR m_alphaCursor;
#endif
/* Common flags: */
bool m_fIsFirstTimeStarted : 1;
bool m_fIsIgnoreRuntimeMediumsChanging : 1;
bool m_fIsGuestResizeIgnored : 1;
bool m_fIsSeamlessModeRequested : 1;
bool m_fIsAutoCaptureDisabled : 1;
bool m_fReconfigurable : 1;
/* Guest additions flags: */
ULONG m_ulGuestAdditionsRunLevel;
bool m_fIsGuestSupportsGraphics : 1;
bool m_fIsGuestSupportsSeamless : 1;
/* Keyboard flags: */
bool m_fNumLock : 1;
bool m_fCapsLock : 1;
bool m_fScrollLock : 1;
uint m_uNumLockAdaptionCnt;
uint m_uCapsLockAdaptionCnt;
/* Mouse flags: */
bool m_fIsMouseSupportsAbsolute : 1;
bool m_fIsMouseSupportsRelative : 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 // !___UIConsole_h___