UIActionsPool.cpp revision cc81df56fd1209c59bf783586dd5d14ca85aa578
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIActionsPool 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.
*/
/* Local includes */
#include "UIActionsPool.h"
#include "UIIconPool.h"
#include "UIMachineShortcuts.h"
#include "VBoxGlobal.h"
/* Global includes */
#include <QHelpEvent>
#include <QToolTip>
#include <QtGlobal>
/* Extended QMenu class used in UIActions */
{
public:
/* QIMenu constructor: */
bool isToolTipsShown() const { return m_fShowToolTips; }
private:
/* Event handler reimplementation: */
{
/* Handle particular event-types: */
{
/* Tool-tip request handler: */
{
/* Get current help-event: */
/* Get action which caused help-event: */
/* If action present => show action's tool-tip if needed: */
if (pAction && m_fShowToolTips)
break;
}
default:
break;
}
/* Base-class event-handler: */
}
/* Reflects 'show-tool-tip' feature activity: */
bool m_fShowToolTips;
};
/* Action activation event */
class ActivateActionEvent : public QEvent
{
public:
private:
};
{
/* Default is no specific menu role. We will set them explicit later. */
}
{
return m_type;
}
class UISimpleAction : public UIAction
{
public:
{
strIconDis));
}
{
}
};
class UIToggleAction : public UIAction
{
public:
{
strIconDis));
init();
}
{
init();
}
{
init();
}
private slots:
void sltUpdateAppearance()
{
}
private:
void init()
{
setCheckable(true);
}
};
class UIMenuAction : public UIAction
{
public:
{
strIconDis));
}
{
}
};
class MenuMachineAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class PerformTakeSnapshotAction : public UISimpleAction
{
public:
":/take_snapshot_16px.png", ":/take_snapshot_dis_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Take &Snapshot..."), gMS->shortcut(UIMachineShortcuts::TakeSnapshotShortcut)));
}
};
class ShowInformationDialogAction : public UISimpleAction
{
public:
":/session_info_16px.png", ":/session_info_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Session I&nformation"), gMS->shortcut(UIMachineShortcuts::InformationDialogShortcut)));
}
};
class MenuMouseIntegrationAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ToggleMouseIntegrationAction : public UIToggleAction
{
public:
":/mouse_can_seamless_on_16px.png", ":/mouse_can_seamless_16px.png",
":/mouse_can_seamless_on_disabled_16px.png", ":/mouse_can_seamless_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Disable &Mouse Integration"), gMS->shortcut(UIMachineShortcuts::MouseIntegrationShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Temporarily disable host mouse pointer integration"));
}
};
class PerformTypeCADAction : public UISimpleAction
{
public:
":/hostkey_16px.png", ":/hostkey_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Insert Ctrl-Alt-Del"), gMS->shortcut(UIMachineShortcuts::TypeCADShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Send the Ctrl-Alt-Del sequence to the virtual machine"));
}
};
#ifdef Q_WS_X11
class PerformTypeCABSAction : public UISimpleAction
{
public:
":/hostkey_16px.png", ":/hostkey_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Insert Ctrl-Alt-Backspace"), gMS->shortcut(UIMachineShortcuts::TypeCABSShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Send the Ctrl-Alt-Backspace sequence to the virtual machine"));
}
};
#endif
class TogglePauseAction : public UIToggleAction
{
public:
":/pause_16px.png", ":/pause_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Pause"), gMS->shortcut(UIMachineShortcuts::PauseShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Suspend the execution of the virtual machine"));
}
};
class PerformResetAction : public UISimpleAction
{
public:
":/reset_16px.png", ":/reset_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Reset"), gMS->shortcut(UIMachineShortcuts::ResetShortcut)));
}
};
class PerformShutdownAction : public UISimpleAction
{
public:
":/acpi_16px.png", ":/acpi_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "ACPI Sh&utdown"), gMS->shortcut(UIMachineShortcuts::ShutdownShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Send the ACPI Power Button press event to the virtual machine"));
}
};
class PerformCloseAction : public UISimpleAction
{
public:
":/exit_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Close..."), gMS->shortcut(UIMachineShortcuts::CloseShortcut)));
}
};
class MenuViewAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ToggleFullscreenModeAction : public UIToggleAction
{
public:
":/fullscreen_on_16px.png", ":/fullscreen_16px.png",
":/fullscreen_on_disabled_16px.png", ":/fullscreen_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Switch to &Fullscreen"), gMS->shortcut(UIMachineShortcuts::FullscreenModeShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Switch between normal and fullscreen mode"));
}
};
class ToggleSeamlessModeAction : public UIToggleAction
{
public:
":/seamless_on_16px.png", ":/seamless_16px.png",
":/seamless_on_disabled_16px.png", ":/seamless_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Switch to Seam&less Mode"), gMS->shortcut(UIMachineShortcuts::SeamlessModeShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Switch between normal and seamless desktop integration mode"));
}
};
class ToggleScaleModeAction : public UIToggleAction
{
public:
":/scale_on_16px.png", ":/scale_16px.png",
":/scale_on_disabled_16px.png", ":/scale_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Switch to &Scale Mode"), gMS->shortcut(UIMachineShortcuts::ScaleModeShortcut)));
}
};
class ToggleGuestAutoresizeAction : public UIToggleAction
{
public:
":/auto_resize_on_on_16px.png", ":/auto_resize_on_16px.png",
":/auto_resize_on_on_disabled_16px.png", ":/auto_resize_on_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Auto-resize &Guest Display"), gMS->shortcut(UIMachineShortcuts::GuestAutoresizeShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Automatically resize the guest display when the window is resized (requires Guest Additions)"));
}
};
class PerformWindowAdjustAction : public UISimpleAction
{
public:
":/adjust_win_size_16px.png", ":/adjust_win_size_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Adjust Window Size"), gMS->shortcut(UIMachineShortcuts::WindowAdjustShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Adjust window size and position to best fit the guest display"));
}
};
class MenuDevicesAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class MenuOpticalDevicesAction : public UIMenuAction
{
public:
":/cd_16px.png", ":/cd_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
}
};
class MenuFloppyDevicesAction : public UIMenuAction
{
public:
":/fd_16px.png", ":/fd_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
}
};
class MenuUSBDevicesAction : public UIMenuAction
{
public:
":/usb_16px.png", ":/usb_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
}
};
class MenuNetworkAdaptersAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ShowNetworkAdaptersDialogAction : public UISimpleAction
{
public:
":/nw_16px.png", ":/nw_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Network Adapters..."), gMS->shortcut(UIMachineShortcuts::NetworkAdaptersDialogShortcut)));
}
};
class MenuSharedFoldersAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ShowSharedFoldersDialogAction : public UISimpleAction
{
public:
":/shared_folder_16px.png", ":/shared_folder_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Shared Folders..."), gMS->shortcut(UIMachineShortcuts::SharedFoldersDialogShortcut)));
}
};
class ToggleVRDEServerAction : public UIToggleAction
{
public:
":/vrdp_on_16px.png", ":/vrdp_16px.png",
":/vrdp_on_disabled_16px.png", ":/vrdp_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Enable R&emote Display"), gMS->shortcut(UIMachineShortcuts::VRDPServerShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Enable remote desktop (RDP) connections to this machine"));
}
};
class PerformInstallGuestToolsAction : public UISimpleAction
{
public:
":/guesttools_16px.png", ":/guesttools_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Install Guest Additions..."), gMS->shortcut(UIMachineShortcuts::InstallGuestAdditionsShortcut)));
setStatusTip(QApplication::translate("UIActionsPool", "Mount the Guest Additions installation image"));
}
};
#ifdef VBOX_WITH_DEBUGGER_GUI
class MenuDebugAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ShowStatisticsAction : public UISimpleAction
{
public:
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Statistics...", "debug action"), gMS->shortcut(UIMachineShortcuts::StatisticWindowShortcut)));
}
};
class ShowCommandLineAction : public UISimpleAction
{
public:
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "&Command Line...", "debug action"), gMS->shortcut(UIMachineShortcuts::CommandLineWindowShortcut)));
}
};
class ToggleLoggingAction : public UIToggleAction
{
public:
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIActionsPool", "Enable &Logging...", "debug action"), gMS->shortcut(UIMachineShortcuts::LoggingShortcut)));
}
};
#endif
class MenuHelpAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ShowHelpAction : public UISimpleAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ShowWebAction : public UISimpleAction
{
public:
":/site_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("VBoxProblemReporter", "&VirtualBox Web Site..."), gMS->shortcut(UIMachineShortcuts::WebShortcut)));
setStatusTip(QApplication::translate("VBoxProblemReporter", "Open the browser and go to the VirtualBox product web site"));
}
};
class PerformResetWarningsAction : public UISimpleAction
{
public:
":/reset_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("VBoxProblemReporter", "&Reset All Warnings"), gMS->shortcut(UIMachineShortcuts::ResetWarningsShortcut)));
setStatusTip(QApplication::translate("VBoxProblemReporter", "Go back to showing all suppressed warnings and messages"));
}
};
#ifdef VBOX_WITH_REGISTRATION
class PerformRegisterAction : public UISimpleAction
{
public:
":/register_16px.png", ":/register_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("VBoxProblemReporter", "R&egister VirtualBox..."), gMS->shortcut(UIMachineShortcuts::RegisterShortcut)));
}
};
#endif /* VBOX_WITH_REGISTRATION */
class PerformUpdateAction : public UISimpleAction
{
public:
":/refresh_16px.png", ":/refresh_disabled_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("VBoxProblemReporter", "C&heck for Updates..."), gMS->shortcut(UIMachineShortcuts::UpdateShortcut)));
}
};
class ShowAboutAction : public UISimpleAction
{
public:
":/about_16px.png")
{
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("VBoxProblemReporter", "&About VirtualBox..."), gMS->shortcut(UIMachineShortcuts::AboutShortcut)));
setStatusTip(QApplication::translate("VBoxProblemReporter", "Show a dialog with product information"));
}
};
#ifdef Q_WS_MAC
class DockMenuAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi() {}
};
class DockSettingsMenuAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ToggleDockPreviewMonitorAction : public UIToggleAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ToggleDockDisableMonitorAction : public UIToggleAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
#endif /* Q_WS_MAC */
{
/* "Machine" menu actions: */
#ifdef Q_WS_X11
#endif
/* "View" menu actions: */
/* "Devices" menu actions: */
m_actionsPool[UIActionIndex_Simple_NetworkAdaptersDialog] = new ShowNetworkAdaptersDialogAction(this);
#ifdef VBOX_WITH_DEBUGGER_GUI
/* "Debugger" menu actions: */
#endif
/* "Help" menu actions: */
#ifdef VBOX_WITH_REGISTRATION
#endif /* VBOX_WITH_REGISTRATION */
#ifdef Q_WS_MAC
/* "Dock" menu actions: */
#endif /* Q_WS_MAC */
/* Create all menus */
createMenus();
/* Test all actions were initialized */
for (int i = 0; i < m_actionsPool.size(); ++i)
if (!m_actionsPool.at(i))
AssertMsgFailed(("Action #%d is not created!\n", i));
}
{
for (int i = 0; i < m_actionsPool.size(); ++i)
delete m_actionsPool.at(i);
}
{
}
void UIActionsPool::createMenus()
{
/* On Mac OS X, all QMenu's are consumed by Qt after they are added to
* another QMenu or a QMenuBar. This means we have to recreate all QMenus
* when creating a new QMenuBar. For simplicity we doing this on all
* platforms right now. */
delete m_actionsPool[UIActionIndex_Simple_Help];
delete m_actionsPool[UIActionIndex_Simple_Web];
#ifdef VBOX_WITH_REGISTRATION
#endif /* VBOX_WITH_REGISTRATION */
/* For whatever reason, Qt doesn't fully remove items with a
* ApplicationSpecificRole from the application menu. Although the QAction
* itself is deleted, a dummy entry is leaved back in the menu. Hiding
* before deletion helps. */
#endif /* Q_WS_MAC */
/* Delete the help items as well. This makes sure they are removed also
* from the Application menu. */
delete m_actionsPool[UIActionIndex_Simple_About];
delete m_actionsPool[UIActionIndex_Simple_Update];
#endif
delete m_actionsPool[UIActionIndex_Simple_Close];
/* Menus */
delete m_actionsPool[UIActionIndex_Menu_Machine];
delete m_actionsPool[UIActionIndex_Menu_View];
delete m_actionsPool[UIActionIndex_Menu_Devices];
#ifdef VBOX_WITH_DEBUGGER_GUI
delete m_actionsPool[UIActionIndex_Menu_Debug];
#endif /* VBOX_WITH_DEBUGGER_GUI */
delete m_actionsPool[UIActionIndex_Menu_Help];
#ifdef Q_WS_MAC
delete m_actionsPool[UIActionIndex_Menu_Dock];
#endif /* Q_WS_MAC */
}
{
for (int i = 0; i < m_actionsPool.size(); ++i)
{
/* Skip menus/separators */
continue;
{
{
/* We asynchronously post a special event instead of calling
* pAction->trigger() directly, to let key presses and
* releases be processed correctly by Qt first.
* Note: we assume that nobody will delete the menu item
* corresponding to the key sequence, so that the pointer to
* menu data posted along with the event will remain valid in
* the event handler, at least until the main window is closed. */
return true;
}
}
}
return false;
}
{
{
case VBoxDefs::ActivateActionEventType:
{
// TODO_NEW_CORE
/* The main window and its children can be destroyed at this point (if, for example, the activated menu
* item closes the main window). Detect this situation to prevent calls to destroyed widgets: */
// QWidgetList list = QApplication::topLevelWidgets();
// bool destroyed = list.indexOf(machineWindowWrapper()->machineWindow()) < 0;
// if (!destroyed && machineWindowWrapper()->machineWindow()->statusBar())
// machineWindowWrapper()->machineWindow()->statusBar()->clearMessage();
return true;
}
default:
break;
}
}
#include "UIActionsPool.moc"