UIMachineWindowNormal.cpp revision cc81df56fd1209c59bf783586dd5d14ca85aa578
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIMachineWindowNormal 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 <QDesktopWidget>
#include <QMenuBar>
#include <QTimer>
#include <QContextMenuEvent>
/* Local includes */
#include "VBoxGlobal.h"
#include "VBoxProblemReporter.h"
#include "VBoxUtils.h"
#include "UISession.h"
#include "UIActionsPool.h"
#include "UIIndicatorsPool.h"
#include "UIKeyboardHandler.h"
#include "UIMouseHandler.h"
#include "UIMachineLogic.h"
#include "UIMachineWindowNormal.h"
#include "UIMachineView.h"
#include "UIDownloaderAdditions.h"
#include "UIDownloaderUserManual.h"
#ifdef Q_WS_MAC
# include "UIImageTools.h"
#endif /* Q_WS_MAC */
#include "QIStatusBar.h"
#include "QIStateIndicator.h"
#include "UIHotKeyEditor.h"
, m_pIdleTimer(0)
{
/* "This" is machine window: */
m_pMachineWindow = this;
/* Set the main window in VBoxGlobal */
if (uScreenId == 0)
vboxGlobal().setMainWindow(this);
/* Prepare window icon: */
/* Prepare console connections: */
/* Prepare menu: */
prepareMenu();
/* Prepare status bar: */
/* Prepare connections: */
/* Retranslate normal window finally: */
/* Prepare normal machine view container: */
/* Prepare normal machine view: */
/* Prepare handlers: */
/* Load normal window settings: */
/* Update all the elements: */
#ifdef Q_WS_MAC
/* Beta label? */
if (vboxGlobal().isBeta())
{
::darwinLabelWindow(this, &betaLabel, true);
}
#endif /* Q_WS_MAC */
/* Show window: */
showSimple();
}
{
/* Save normal window settings: */
/* Prepare handlers: */
/* Cleanup normal machine view: */
/* Cleanup status-bar: */
}
{
}
{
if (type == KDeviceType_HardDisk)
if (type == KDeviceType_DVD)
if (type == KDeviceType_Floppy)
}
{
}
{
}
{
}
{
}
void UIMachineWindowNormal::sltTryClose()
{
}
{
/* If there is an additions download running show the process bar: */
}
{
/* If there is an additions download running show the process bar: */
}
{
{
}
{
}
{
}
{
}
{
}
{
}
}
void UIMachineWindowNormal::sltShowIndicatorsContextMenu(QIStateIndicator *pIndicator, QContextMenuEvent *pEvent)
{
{
machineLogic()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu()->exec(pEvent->globalPos());
}
{
machineLogic()->actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu()->exec(pEvent->globalPos());
}
{
machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->exec(pEvent->globalPos());
}
{
machineLogic()->actionsPool()->action(UIActionIndex_Menu_NetworkAdapters)->menu()->exec(pEvent->globalPos());
}
{
machineLogic()->actionsPool()->action(UIActionIndex_Menu_SharedFolders)->menu()->exec(pEvent->globalPos());
}
{
machineLogic()->actionsPool()->action(UIActionIndex_Menu_MouseIntegration)->menu()->exec(pEvent->globalPos());
}
}
void UIMachineWindowNormal::sltProcessGlobalSettingChange(const char * /* aPublicName */, const char * /* aName */)
{
m_pNameHostkey->setText(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo()));
}
void UIMachineWindowNormal::retranslateUi()
{
/* Translate parent class: */
"This key, when pressed alone, toggles the keyboard and mouse "
"capture state. It can also be used in combination with other keys "
"to quickly perform actions from the main menu."));
m_pNameHostkey->setText(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo()));
}
{
/* Update parent-class window: */
/* Update that machine window: */
if (iElement & UIVisualElement_HDStuff)
if (iElement & UIVisualElement_CDStuff)
if (iElement & UIVisualElement_FDStuff)
if (iElement & UIVisualElement_USBStuff &&
}
{
{
{
if (!isMaximizedChecked())
{
#ifdef VBOX_WITH_DEBUGGER_GUI
/* Update debugger window position */
#endif
}
break;
}
{
if (!isMaximizedChecked())
{
#ifdef VBOX_WITH_DEBUGGER_GUI
/* Update debugger window position */
#endif
}
break;
}
default:
break;
}
}
#ifdef Q_WS_X11
{
}
#endif
{
}
{
/* Base-class connections: */
/* Medium change updater: */
/* USB controller change updater: */
this, SLOT(sltUSBControllerChange()));
/* USB device state-change updater: */
connect(machineLogic()->uisession(), SIGNAL(sigUSBDeviceStateChange(const CUSBDevice &, bool, const CVirtualBoxErrorInfo &)),
this, SLOT(sltUSBDeviceStateChange()));
/* Network adapter change updater: */
this, SLOT(sltNetworkAdapterChange()));
/* Shared folder change updater: */
this, SLOT(sltSharedFolderChange()));
}
void UIMachineWindowNormal::prepareMenu()
{
}
{
/* Common setup: */
setStatusBar(new QIStatusBar(this));
/* Hard Disks: */
/* Optical Disks: */
/* Floppy Disks: */
/* USB Devices: */
/* Network Adapters: */
QIStateIndicator *pLedNetworkAdapters = indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters);
/* Shared Folders: */
/* Virtualization: */
/* Separator: */
/* Mouse: */
/* Host Key: */
m_pCntHostkey = new QWidget;
m_pNameHostkey = new QLabel(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo()));
/* Add to statusbar: */
/* Add the additions downloader progress bar to the status bar,
* if a download is actually running: */
/* Add the user manual progress bar to the status bar,
* if a download is actually running: */
/* Create & start timer to update LEDs: */
m_pIdleTimer = new QTimer(this);
#ifdef Q_WS_MAC
/* For the status bar on Cocoa: */
#endif
}
{
/* Setup global settings change updater: */
this, SLOT(sltProcessGlobalSettingChange(const char *, const char *)));
/* Setup additions downloader listener: */
connect(machineLogic(), SIGNAL(sigDownloaderAdditionsCreated()), this, SLOT(sltDownloaderAdditionsEmbed()));
/* Setup user manual downloader listener: */
connect(&vboxProblem(), SIGNAL(sigDownloaderUserManualCreated()), this, SLOT(sltDownloaderUserManualEmbed()));
}
{
#ifdef VBOX_WITH_VIDEOHWACCEL
/* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled: */
bool bAccelerate2DVideo = session().GetMachine().GetAccelerate2DVideoEnabled() && VBoxGlobal::isAcceleration2DVideoAvailable();
#endif
/* Set central widget: */
setCentralWidget(new QWidget);
/* Set central widget layout: */
, machineLogic()->visualStateType()
#ifdef VBOX_WITH_VIDEOHWACCEL
#endif
);
/* Add machine view into layout: */
/* Setup machine view connections: */
if (machineView())
{
/* Keyboard state-change updater: */
connect(machineLogic()->keyboardHandler(), SIGNAL(keyboardStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Hostkey), SLOT(setState(int)));
/* Mouse state-change updater: */
connect(machineLogic()->mouseHandler(), SIGNAL(mouseStateChanged(int)), indicatorsPool()->indicator(UIIndicatorIndex_Mouse), SLOT(setState(int)));
/* Early initialize required connections: */
indicatorsPool()->indicator(UIIndicatorIndex_Hostkey)->setState(machineLogic()->keyboardHandler()->keyboardState());
indicatorsPool()->indicator(UIIndicatorIndex_Mouse)->setState(machineLogic()->mouseHandler()->mouseState());
}
/* The background has to go black: */
centralWidget()->setAutoFillBackground(true);
setAutoFillBackground(true);
#endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */
}
{
/* Load normal window settings: */
/* Load extra-data settings: */
{
QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastNormalWindowPosition) :
int x = 0, y = 0, w = 0, h = 0;
else ok = false;
else ok = false;
else ok = false;
else ok = false;
/* If previous parameters were read correctly: */
if (ok)
{
/* If previous machine state is SAVED: */
{
/* Restore window size and position: */
m_normalGeometry = QRect(x, y, w, h);
}
/* If previous machine state is not SAVED: */
else
{
/* Restore only window position: */
if (machineView())
}
/* Maximize if needed: */
if (max)
}
else
{
/* Normalize view early to the optimal size: */
if (machineView())
/* Move newly created window to the screen center: */
m_normalGeometry = geometry();
}
/* Normalize view to the optimal size:
* Note: Cause of the async behavior of X11 (at least GNOME) we have to delay this a little bit.
* On Mac OS X and MS Windows this is not necessary and create even wrong resize events.
* So there we set the geometry immediately. */
if (machineView())
#ifdef Q_WS_X11
#else /* Q_WS_X11 */
machineView()->normalizeGeometry(true);
#endif /* !Q_WS_X11 */
}
/* Load availability settings: */
{
/* USB Stuff: */
if ( usbController.isNull()
|| !usbController.GetEnabled()
|| !usbController.GetProxyAvailable())
{
/* Hide USB Menu: */
}
else
{
/* Toggle USB LED: */
}
}
/* Load global settings: */
{
}
}
{
/* Save extra-data settings: */
{
if (isMaximizedChecked())
QString strPositionAddress = m_uScreenId == 0 ? QString("%1").arg(VBoxDefs::GUI_LastNormalWindowPosition) :
}
}
{
/* Do not cleanup machine view if it is not present: */
if (!machineView())
return;
m_pMachineView = 0;
}
{
/* Stop LED-update timer: */
m_pIdleTimer->stop();
}
void UIMachineWindowNormal::showSimple()
{
/* Just show window: */
show();
}
{
#ifdef Q_WS_MAC
/* On the Mac the WindowStateChange signal doesn't seems to be delivered
* when the user get out of the maximized state. So check this ourself. */
return ::darwinIsWindowMaximized(this);
#else /* Q_WS_MAC */
return isMaximized();
#endif /* !Q_WS_MAC */
}