UIMachine.cpp revision eb9b4d0a3abf0bff7bbfff28039e4fc46be595e5
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIMachine class implementation
*/
/*
* Copyright (C) 2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/* Global includes */
#include <QTimer>
/* Local includes */
#include "VBoxGlobal.h"
#include "UIMachine.h"
#include "UISession.h"
#include "UIActionPoolRuntime.h"
#include "UIMachineLogic.h"
#include "UIMachineWindow.h"
#ifdef Q_WS_MAC
# include <ApplicationServices/ApplicationServices.h>
#endif /* Q_WS_MAC */
class UIVisualState : public QObject
{
public:
/* Visual state holder constructor: */
, m_pMachineLogic(0)
#ifdef Q_WS_MAC
#endif /* Q_WS_MAC */
{
/* Connect state-change handler: */
connect(this, SIGNAL(sigChangeVisualState(UIVisualStateType)), parent(), SLOT(sltChangeVisualState(UIVisualStateType)));
}
/* Public getters: */
virtual UIVisualStateType visualStateType() const = 0;
{
#ifdef Q_WS_MAC
/* If the new is or the old type was fullscreen we add the blending
* transition between the mode switches.
* TODO: make this more general. */
if ( fResult
&& ( visualStateType() == UIVisualStateType_Fullscreen
{
/* Fade to black */
CGDisplayFade(m_fadeToken, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, true);
}
#else /* Q_WS_MAC */
#endif /* !Q_WS_MAC */
return fResult;
}
virtual void change() = 0;
virtual void finishChange()
{
#ifdef Q_WS_MAC
/* If there is a valid fade token, fade back to normal color in any
* case. */
{
/* Fade back to the normal gamma */
CGDisplayFade(m_fadeToken, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, false);
}
#endif /* Q_WS_MAC */
}
/* Signal to change-state: */
protected:
/* Protected members: */
#ifdef Q_WS_MAC
#endif /* Q_WS_MAC */
};
class UIVisualStateNormal : public UIVisualState
{
public:
/* Normal visual state holder constructor: */
void change()
{
/* Connect action handlers: */
/* Initialize the logic object: */
}
private slots:
void sltGoToFullscreenMode()
{
/* Change visual state to fullscreen: */
}
void sltGoToSeamlessMode()
{
/* Change visual state to seamless: */
}
void sltGoToScaleMode()
{
/* Change visual state to scale: */
}
};
class UIVisualStateFullscreen : public UIVisualState
{
public:
/* Fullscreen visual state holder constructor: */
{
/* This visual state should take care of own action: */
if (!pActionFullscreen->isChecked())
{
pActionFullscreen->blockSignals(true);
pActionFullscreen->setChecked(true);
pActionFullscreen->blockSignals(false);
}
}
/* Fullscreen visual state holder destructor: */
virtual ~UIVisualStateFullscreen()
{
/* This visual state should take care of own action: */
if (pActionFullscreen->isChecked())
{
pActionFullscreen->blockSignals(true);
pActionFullscreen->setChecked(false);
pActionFullscreen->blockSignals(false);
}
}
void change()
{
/* Connect action handlers: */
/* Initialize the logic object: */
}
private slots:
void sltGoToNormalMode()
{
/* Change visual state to normal: */
}
void sltGoToSeamlessMode()
{
/* Change visual state to seamless: */
}
void sltGoToScaleMode()
{
/* Change visual state to scale: */
}
};
class UIVisualStateSeamless : public UIVisualState
{
public:
/* Seamless visual state holder constructor: */
{
/* This visual state should take care of own action: */
if (!pActionSeamless->isChecked())
{
pActionSeamless->blockSignals(true);
pActionSeamless->setChecked(true);
pActionSeamless->blockSignals(false);
}
}
/* Seamless visual state holder destructor: */
virtual ~UIVisualStateSeamless()
{
/* This visual state should take care of own action: */
if (pActionSeamless->isChecked())
{
pActionSeamless->blockSignals(true);
pActionSeamless->setChecked(false);
pActionSeamless->blockSignals(false);
}
}
void change()
{
/* Connect action handlers: */
/* Initialize the logic object: */
}
private slots:
void sltGoToNormalMode()
{
/* Change visual state to normal: */
}
void sltGoToFullscreenMode()
{
/* Change visual state to fullscreen: */
}
void sltGoToScaleMode()
{
/* Change visual state to scale: */
}
};
class UIVisualStateScale : public UIVisualState
{
public:
/* Scale visual state holder constructor: */
{
/* This visual state should take care of own action: */
if (!pActionScale->isChecked())
{
pActionScale->blockSignals(true);
pActionScale->setChecked(true);
pActionScale->blockSignals(false);
}
}
/* Seamless visual state holder destructor: */
virtual ~UIVisualStateScale()
{
/* This visual state should take care of own action: */
if (pActionScale->isChecked())
{
pActionScale->blockSignals(true);
pActionScale->setChecked(false);
pActionScale->blockSignals(false);
}
}
void change()
{
/* Connect action handlers: */
/* Initialize the logic object: */
}
private slots:
void sltGoToNormalMode()
{
/* Change visual state to normal: */
}
void sltGoToFullscreenMode()
{
/* Change visual state to fullscreen: */
}
void sltGoToSeamlessMode()
{
/* Change visual state to seamless: */
}
};
: QObject(0)
, m_pSession(0)
, m_pVisualState(0)
{
/* Storing self: */
if (m_ppThis)
*m_ppThis = this;
/* Create UISession object: */
/* Preventing application from closing in case of window(s) closed: */
qApp->setQuitOnLastWindowClosed(false);
/* Cache IMedium data: */
/* Load machine settings: */
/* Enter default (normal) state */
}
{
/* Save machine settings: */
/* Erase itself pointer: */
*m_ppThis = 0;
/* Delete uisession children in backward direction: */
delete m_pVisualState;
m_pVisualState = 0;
delete m_pSession;
m_pSession = 0;
/* Quit application: */
QApplication::quit();
}
{
if (machineLogic() &&
machineLogic()->mainMachineWindow() &&
else
return 0;
}
{
/* Create new state: */
UIVisualState *pNewVisualState = 0;
switch (visualStateType)
{
case UIVisualStateType_Normal:
{
/* Create normal visual state: */
break;
}
{
/* Create fullscreen visual state: */
break;
}
{
/* Create seamless visual state: */
break;
}
case UIVisualStateType_Scale:
{
/* Create scale visual state: */
break;
}
default:
break;
}
if (m_pVisualState)
/* First we have to check if the selected mode is available at all.
* Only then we delete the old mode and switch to the new mode. */
{
/* Delete previous state: */
delete m_pVisualState;
/* Set the new mode as current mode: */
m_pVisualState->change();
/* Finish any setup: */
}
else
{
/* Discard the temporary created new state: */
delete pNewVisualState;
/* If there is no state currently created => we have to exit: */
if (!m_pVisualState)
deleteLater();
}
}
void UIMachine::sltCloseVirtualMachine()
{
delete this;
}
void UIMachine::enterInitialVisualState()
{
}
{
return m_pVisualState->machineLogic();
else
return 0;
}
void UIMachine::loadMachineSettings()
{
/* Load machine settings: */
/* Load extra-data settings: */
{
/* Machine while saving own settings will save "yes" only for current
* visual representation mode if its differs from normal mode of course.
* But user can alter extra data manually in machine xml file and set there
* more than one visual representation mode flags. Shame on such user!
* There is no reason to enter in more than one visual representation mode
* at machine start, so we are choosing first of requested modes: */
bool fIsSomeExtendedModeChosen = false;
{
/* Test 'scale' flag: */
if (strScaleSettings == "on")
{
fIsSomeExtendedModeChosen = true;
/* We can enter scale mode initially: */
}
}
{
/* Test 'seamless' flag: */
if (strSeamlessSettings == "on")
{
fIsSomeExtendedModeChosen = true;
/* We can't enter seamless mode initially,
* so we should ask ui-session for that: */
uisession()->setSeamlessModeRequested(true);
}
}
{
/* Test 'fullscreen' flag: */
if (strFullscreenSettings == "on")
{
fIsSomeExtendedModeChosen = true;
/* We can enter fullscreen mode initially: */
}
}
}
}
void UIMachine::saveMachineSettings()
{
/* Save machine settings: */
/* Save extra-data settings: */
{
/* Set 'scale' flag: */
/* Set 'seamless' flag: */
/* Set 'fullscreen' flag: */
}
}
#include "UIMachine.moc"