UIMachineWindow.cpp revision 36545c63b2aab948161e4a712913a4f2dce17d2f
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIMachineWindow 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 <QCloseEvent>
#include <QTimer>
#ifdef VBOX_BLEEDING_EDGE
# include <iprt/buildconfig.h>
#endif /* VBOX_BLEEDING_EDGE */
/* Local includes */
#include "COMDefs.h"
#include "VBoxGlobal.h"
#include "UIMessageCenter.h"
#include "UIKeyboardHandler.h"
#include "UIMachineLogic.h"
#include "UIMachineView.h"
#include "UIMachineWindow.h"
#include "UIMachineWindowFullscreen.h"
#include "UIMachineWindowNormal.h"
#include "UIMachineWindowScale.h"
#include "UIMachineWindowSeamless.h"
#include "UIMouseHandler.h"
#include "UISession.h"
#include "UIVMCloseDialog.h"
#ifdef Q_WS_X11
#endif
UIMachineWindow* UIMachineWindow::create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType, ulong uScreenId)
{
UIMachineWindow *window = 0;
switch (visualStateType)
{
case UIVisualStateType_Normal:
break;
break;
break;
case UIVisualStateType_Scale:
break;
}
return window;
}
{
delete pWhichWindow;
}
void UIMachineWindow::sltTryClose()
{
/* Do not try to close if restricted: */
if (machineLogic()->isPreventAutoClose())
return;
/* First close any open modal & popup widgets.
* Use a single shot with timeout 0 to allow the widgets to cleanly close and test then again.
* If all open widgets are closed destroy ourself: */
QApplication::activePopupWidget() : 0;
if (widget)
{
}
else
machineWindow()->close();
}
, m_pMachineWindow(0)
, m_pTopSpacer(0)
, m_pBottomSpacer(0)
, m_pLeftSpacer(0)
, m_pRightSpacer(0)
, m_pMachineView(0)
{
}
{
/* Close any opened modal & popup widgets: */
{
* because deleteLater() is synchronous
* and will be called later than this destructor: */
* because deleteLater() is synchronous
* and will be called later than this destructor: */
pWidget->deleteLater();
}
}
{
return machineLogic()->uisession();
}
{
}
{
}
void UIMachineWindow::retranslateUi()
{
#ifdef VBOX_BLEEDING_EDGE
.arg(RTBldCfgVersion())
#endif
}
#ifdef Q_WS_X11
{
// TODO: Check if that is still required!
/* Qt bug: when the machine-view grabs the keyboard,
* FocusIn, FocusOut, WindowActivate and WindowDeactivate Qt events are
* not properly sent on top level window deactivation.
* The fix is to substiute the mode in FocusOut X11 event structure
* to NotifyNormal to cause Qt to process it as desired. */
{
{
}
}
return false;
}
#endif
{
/* Always ignore close event: */
/* Should we close application? */
bool fCloseApplication = false;
switch (uisession()->machineState())
{
case KMachineState_Running:
case KMachineState_Paused:
case KMachineState_Stuck:
case KMachineState_Teleporting: // TODO: Test this!
case KMachineState_TeleportingPausedVM: // TODO: Test this!
{
/* Get the machine: */
/* Prepare close dialog: */
/* Assign close-dialog pixmap: */
/* Check which close actions are disallowed: */
QStringList restictedActionsList = machine.GetExtraData(VBoxDefs::GUI_RestrictedCloseActions).split(',');
bool fIsPowerOffAndRestoreAllowed = fIsPowerOffAllowed && !restictedActionsList.contains("Restore", Qt::CaseInsensitive);
/* Make the Restore Snapshot checkbox visible/hidden depending on snapshots count & restrictions: */
dlg.mCbDiscardCurState->setText(dlg.mCbDiscardCurState->text().arg(machine.GetCurrentSnapshot().GetName()));
/* Choice string tags for close-dialog: */
/* Read the last user's choice for the given VM: */
/* Check which button should be initially chosen: */
QRadioButton *pRadioButton = 0;
/* If choosing 'last choice' is possible: */
{
}
{
}
{
}
/* Else 'default choice' will be used: */
else
{
if (fIsACPIShutdownAllowed && isACPIEnabled)
else if (fIsPowerOffAllowed)
else if (fIsStateSavingAllowed)
}
/* If some radio button was chosen: */
if (pRadioButton)
{
/* Check and focus it: */
pRadioButton->setChecked(true);
pRadioButton->setFocus();
}
/* If no one of radio buttons was chosen: */
else
{
/* Just break and leave: */
break;
}
/* This flag will keep the status of every further logical operation: */
bool success = true;
/* Pause before showing dialog if necessary: */
if (!fWasPaused)
if (success)
{
/* Preventing auto-closure: */
machineLogic()->setPreventAutoClose(true);
/* If close dialog accepted: */
{
/* Get current console: */
success = false;
{
else
{
/* Show the "VM saving" progress dialog: */
msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_state_save_90px.png", 0, true);
if (progress.GetResultCode() != 0)
else
success = true;
}
if (success)
fCloseApplication = true;
}
{
/* Unpause the VM to let it grab the ACPI shutdown event: */
/* Prevent the subsequent unpause request: */
fWasPaused = true;
/* Signal ACPI shutdown (if there is no ACPI device, the operation will fail): */
else
success = true;
}
{
else
{
/* Show the power down progress dialog: */
msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_poweroff_90px.png", 0, true);
if (progress.GetResultCode() != 0)
else
success = true;
}
if (success)
{
/* Discard the current state if requested: */
{
else
{
/* Show the progress dialog: */
msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png", 0, true);
if (progress.GetResultCode() != 0)
}
}
}
if (success)
fCloseApplication = true;
}
if (success)
{
/* Read the last user's choice for the given VM: */
/* Memorize the last user's choice for the given VM: */
else
AssertFailed();
}
}
/* Restore the running state if needed: */
if (success && !fCloseApplication && !fWasPaused && uisession()->machineState() == KMachineState_Paused)
/* Allowing auto-closure: */
machineLogic()->setPreventAutoClose(false);
}
break;
}
default:
break;
}
if (fCloseApplication)
{
/* VM has been powered off or saved. We must *safely* close the VM window(s): */
}
}
void UIMachineWindow::prepareWindowIcon()
{
/* The default application icon (will be changed to VM-specific icon little bit later):
* 1. On Win32, it's built-in to the executable;
* 2. On Mac OS X the icon referenced in info.plist is used. */
#endif
#ifndef Q_WS_MAC
/* Set the VM-specific application icon except Mac OS X: */
machineWindow()->setWindowIcon(vboxGlobal().vmGuestOSTypeIcon(session().GetMachine().GetOSTypeId()));
#endif
}
{
/* Machine state-change updater: */
QObject::connect(uisession(), SIGNAL(sigMachineStateChange()), machineWindow(), SLOT(sltMachineStateChanged()));
}
{
/* Create view container.
* After it will be passed to parent widget of some mode,
* there will be no need to delete it, so no need to cleanup: */
m_pMachineViewContainer = new QGridLayout();
/* Create and add shifting spacers.
* After they will be inserted into layout, it will get the parentness
* of those spacers, so there will be no need to cleanup them. */
}
void UIMachineWindow::prepareHandlers()
{
/* Register keyboard-handler: */
/* Register mouse-handler: */
}
void UIMachineWindow::cleanupHandlers()
{
/* Unregister mouse-handler: */
/* Unregister keyboard-handler: */
}
{
{
/* Get machine state: */
/* Prepare full name: */
if (machine.GetSnapshotCount() > 0)
{
}
if (state != KMachineState_Null)
/* Unusual on the Mac. */
#ifndef Q_WS_MAC
#endif /* Q_WS_MAC */
}
}
#ifdef VBOX_WITH_DEBUGGER_GUI
void UIMachineWindow::updateDbgWindows()
{
/* The debugger windows are bind to the main VM window. */
if (m_uScreenId == 0)
}
#endif /* VBOX_WITH_DEBUGGER_GUI */
{
}