UIActionPool.cpp revision f36543a0783c9fadf211ea3e98ef6578f5736ccd
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIActionPool class implementation
*/
/*
* Copyright (C) 2010-2011 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 <QHelpEvent>
#include <QToolTip>
/* Local includes: */
#include "UIActionPool.h"
#include "UIIconPool.h"
#include "VBoxGlobal.h"
#include "UISelectorShortcuts.h"
#include "UIMachineShortcuts.h"
/* Action activation event: */
class ActivateActionEvent : public QEvent
{
public:
private:
};
/* UIActionInterface stuff: */
{
/* By default there is no specific menu role.
* It will be set explicitly later. */
}
/* UIMenuInterface stuff: */
: m_fShowToolTips(false)
{
}
{
/* 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: */
}
/* UISimpleAction stuff: */
{
}
{
setIcon(UIIconPool::iconSetFull(normalSize, smallSize, strNormalIcon, strSmallIcon, strNormalIconDis, strSmallIconDis));
}
{
}
/* UIStateAction stuff: */
{
}
{
setIcon(UIIconPool::iconSetFull(normalSize, smallSize, strNormalIcon, strSmallIcon, strNormalIconDis, strSmallIconDis));
}
{
}
/* UIToggleAction stuff: */
{
init();
}
{
setIcon(UIIconPool::iconSetFull(normalSize, smallSize, strNormalIcon, strSmallIcon, strNormalIconDis, strSmallIconDis));
init();
}
{
init();
}
{
init();
}
void UIToggleAction::sltUpdateAppearance()
{
}
void UIToggleAction::init()
{
setCheckable(true);
}
/* UIMenuAction stuff: */
{
setMenu(new UIMenuInterface);
}
{
setMenu(new UIMenuInterface);
}
class MenuHelpAction : public UIMenuAction
{
public:
{
}
protected:
void retranslateUi()
{
}
};
class ShowHelpAction : public UISimpleAction
{
public:
{
switch (gActionPool->type())
{
break;
case UIActionPoolType_Runtime:
break;
}
}
protected:
void retranslateUi()
{
}
};
class ShowWebAction : public UISimpleAction
{
public:
{
switch (gActionPool->type())
{
break;
case UIActionPoolType_Runtime:
break;
}
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIMessageCenter", "&VirtualBox Web Site..."), gMS->shortcut(UIMachineShortcuts::WebShortcut)));
setStatusTip(QApplication::translate("UIMessageCenter", "Open the browser and go to the VirtualBox product web site"));
}
};
class PerformResetWarningsAction : public UISimpleAction
{
public:
{
switch (gActionPool->type())
{
break;
case UIActionPoolType_Runtime:
break;
}
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIMessageCenter", "&Reset All Warnings"), gMS->shortcut(UIMachineShortcuts::ResetWarningsShortcut)));
setStatusTip(QApplication::translate("UIMessageCenter", "Go back to showing all suppressed warnings and messages"));
}
};
class ShowNetworkAccessManagerAction : public UISimpleAction
{
public:
{
switch (gActionPool->type())
{
break;
case UIActionPoolType_Runtime:
break;
}
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIMessageCenter", "Network Access Manager..."), gMS->shortcut(UIMachineShortcuts::NetworkAccessManager)));
}
};
#ifdef VBOX_WITH_REGISTRATION
class PerformRegisterAction : public UISimpleAction
{
public:
{
switch (gActionPool->type())
{
break;
case UIActionPoolType_Runtime:
break;
}
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIMessageCenter", "R&egister VirtualBox..."), gMS->shortcut(UIMachineShortcuts::RegisterShortcut)));
}
};
#endif /* VBOX_WITH_REGISTRATION */
class PerformUpdateAction : public UISimpleAction
{
public:
{
switch (gActionPool->type())
{
break;
case UIActionPoolType_Runtime:
break;
}
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIMessageCenter", "C&heck for Updates..."), gMS->shortcut(UIMachineShortcuts::UpdateShortcut)));
}
};
class ShowAboutAction : public UISimpleAction
{
public:
{
switch (gActionPool->type())
{
break;
case UIActionPoolType_Runtime:
break;
}
}
protected:
void retranslateUi()
{
setText(vboxGlobal().insertKeyToActionText(QApplication::translate("UIMessageCenter", "&About VirtualBox..."), gMS->shortcut(UIMachineShortcuts::AboutShortcut)));
}
};
/* UIActionPool stuff: */
/* static */
{
return m_pInstance;
}
{
/* Prepare instance: */
if (!m_pInstance)
m_pInstance = this;
}
{
/* Cleanup instance: */
if (m_pInstance == this)
m_pInstance = 0;
}
void UIActionPool::prepare()
{
/* Create actions: */
/* Create menus: */
createMenus();
}
void UIActionPool::cleanup()
{
/* Destroy pool: */
destroyPool();
}
{
/* Get the list of keys: */
/* Iterate through the whole list of keys: */
{
/* Get current action: */
/* Skip menus/separators: */
continue;
/* Get the hot key of the current action: */
{
{
/* 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;
}
void UIActionPool::createActions()
{
/* 'Help' actions: */
#ifdef VBOX_WITH_REGISTRATION
#endif /* VBOX_WITH_REGISTRATION */
}
void UIActionPool::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. */
/* Recreate 'help' menu items as well.
* This makes sure they are removed also from the Application menu: */
delete m_pool[UIActionIndex_Simple_Help];
delete m_pool[UIActionIndex_Simple_Web];
delete m_pool[UIActionIndex_Simple_ResetWarnings];
#ifdef VBOX_WITH_REGISTRATION
delete m_pool[UIActionIndex_Simple_Register]
#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
delete m_pool[UIActionIndex_Simple_Update];
delete m_pool[UIActionIndex_Simple_About];
#endif
/* 'Help' menu itself: */
delete m_pool[UIActionIndex_Menu_Help];
}
void UIActionPool::destroyPool()
{
/* Get the list of keys: */
/* Delete all the items of the map: */
}
{
/* Depending on event-type: */
{
case VBoxDefs::ActivateActionEventType:
{
/* Process specific event: */
return true;
}
default:
break;
}
/* Pass to the base-class: */
}
#include "UIActionPool.moc"