UIMachineWindowNormal.cpp revision 9f72be0517ae135bdd3e6ee140d3321b40aeb6e7
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIMachineWindowNormal class implementation
*/
/*
* Copyright (C) 2010-2012 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.
*/
/* Qt includes: */
#include <QDesktopWidget>
#include <QMenuBar>
#include <QTimer>
#include <QContextMenuEvent>
#include <QResizeEvent>
/* GUI includes: */
#include "VBoxGlobal.h"
#include "UISession.h"
#include "UIActionPoolRuntime.h"
#include "UIIndicatorsPool.h"
#include "UIKeyboardHandler.h"
#include "UIMouseHandler.h"
#include "UIMachineLogic.h"
#include "UIMachineWindowNormal.h"
#include "UIMachineView.h"
#include "QIStatusBar.h"
#include "QIStateIndicator.h"
#include "UIHotKeyEditor.h"
#ifdef Q_WS_MAC
# include "VBoxUtils.h"
# include "UIImageTools.h"
#endif /* Q_WS_MAC */
/* COM includes: */
#include "CConsole.h"
#include "CMediumAttachment.h"
#include "CUSBController.h"
, m_pIdleTimer(0)
{
}
{
/* Call to base-class: */
/* Update pause and virtualization stuff: */
}
{
/* Update corresponding medium stuff: */
if (type == KDeviceType_HardDisk)
if (type == KDeviceType_DVD)
if (type == KDeviceType_Floppy)
}
{
/* Update USB stuff: */
}
{
/* Update USB stuff: */
}
{
/* Update network stuff: */
}
{
/* Update shared-folders stuff: */
}
{
/* Update virtualization stuff: */
}
{
/* Update LEDs: */
updateIndicatorState(indicatorsPool()->indicator(UIIndicatorIndex_HardDisks), KDeviceType_HardDisk);
updateIndicatorState(indicatorsPool()->indicator(UIIndicatorIndex_FloppyDisks), KDeviceType_Floppy);
updateIndicatorState(indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters), KDeviceType_Network);
updateIndicatorState(indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders), KDeviceType_SharedFolder);
}
void UIMachineWindowNormal::sltShowIndicatorsContextMenu(QIStateIndicator *pIndicator, QContextMenuEvent *pEvent)
{
{
}
/* Show floppy drive LED context menu: */
{
}
/* Show USB device LED context menu: */
{
}
/* Show network adapter LED context menu: */
{
}
/* Show shared-folders LED context menu: */
{
}
/* Show mouse LED context menu: */
{
}
}
void UIMachineWindowNormal::sltProcessGlobalSettingChange(const char * /* aPublicName */, const char * /* aName */)
{
/* Update host-combination LED: */
m_pNameHostkey->setText(UIHotKeyCombination::toReadableString(vboxGlobal().settings().hostCombo()));
}
{
/* Call to base-class: */
/* 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()));
/* CPU execution cap change updater: */
this, SLOT(sltCPUExecutionCapChange()));
}
void UIMachineWindowNormal::prepareMenu()
{
/* Call to base-class: */
/* Prepare menu-bar: */
}
{
/* Call to base-class: */
/* 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 status-bar: */
/* Create & start timer to update LEDs: */
m_pIdleTimer = new QTimer(this);
#ifdef Q_WS_MAC
/* For the status-bar on Cocoa: */
#endif /* Q_WS_MAC */
}
{
/* Call to base-class: */
/* The background has to go black: */
centralWidget()->setAutoFillBackground(true);
setAutoFillBackground(true);
#endif /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */
/* Make sure host-combination LED will be updated: */
this, SLOT(sltProcessGlobalSettingChange(const char *, const char *)));
#ifdef Q_WS_MAC
/* Beta label? */
if (vboxGlobal().isBeta())
{
::darwinLabelWindow(this, &betaLabel, true);
}
#endif /* Q_WS_MAC */
}
void UIMachineWindowNormal::prepareHandlers()
{
/* Call to base-class: */
/* 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());
}
void UIMachineWindowNormal::loadSettings()
{
/* Call to base-class: */
/* Get machine: */
/* Load extra-data settings: */
{
/* Load window position settings: */
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: */
if (m.GetState() == KMachineState_Saved)
{
/* Restore window size and position: */
m_normalGeometry = QRect(x, y, w, h);
}
/* If previous machine state was not SAVED: */
else
{
/* Restore only window position: */
if (machineView())
machineView()->normalizeGeometry(false);
}
/* Maximize if needed: */
if (max)
}
else
{
/* Normalize view early to the optimal size: */
if (machineView())
machineView()->normalizeGeometry(true);
/* Move newly created window to the screen center: */
m_normalGeometry = geometry();
}
/* Normalize view to the optimal size: */
if (machineView())
machineView()->normalizeGeometry(true);
}
/* Load availability settings: */
{
/* USB Stuff: */
if ( usbController.isNull()
|| !usbController.GetEnabled()
|| !usbController.GetProxyAvailable())
{
/* Hide USB menu: */
}
else
{
/* Toggle USB LED: */
}
}
/* Load global settings: */
{
m_pIdleTimer->stop();
}
}
void UIMachineWindowNormal::saveSettings()
{
/* Get machine: */
/* Save extra-data settings: */
{
if (isMaximizedChecked())
}
/* Call to base-class: */
}
{
/* Stop LED-update timer: */
m_pIdleTimer->stop();
/* Call to base-class: */
}
void UIMachineWindowNormal::retranslateUi()
{
/* Call to base-class: */
/* Translate host-combo LED: */
"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()));
}
{
{
{
if (!isMaximizedChecked())
{
#ifdef VBOX_WITH_DEBUGGER_GUI
/* Update debugger window position: */
#endif /* VBOX_WITH_DEBUGGER_GUI */
}
break;
}
{
if (!isMaximizedChecked())
{
#ifdef VBOX_WITH_DEBUGGER_GUI
/* Update debugger window position: */
#endif /* VBOX_WITH_DEBUGGER_GUI */
}
break;
}
default:
break;
}
}
{
/* Show window if we have to: */
show();
/* Else hide window: */
else
hide();
}
{
/* Call to base-class: */
/* Update machine window content: */
{
{
m_pIdleTimer->stop();
}
}
if (iElement & UIVisualElement_HDStuff)
if (iElement & UIVisualElement_CDStuff)
if (iElement & UIVisualElement_FDStuff)
if (iElement & UIVisualElement_USBStuff &&
}
{
#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 */
}
void UIMachineWindowNormal::updateIndicatorState(QIStateIndicator *pIndicator, KDeviceType deviceType)
{
/* Do NOT update indicators with NULL state: */
return;
/* Paused VM have all indicator states set to IDLE: */
if (fPaused)
{
/* If state differs from IDLE => set IDLE one: */
}
else
{
/* Get current indicator state: */
/* If state differs => set new one: */
}
}