[30677] | 1 | /* $Id: UIConsoleEventHandler.cpp 35722 2011-01-26 16:37:16Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | *
|
---|
| 4 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
| 5 | * UIConsoleEventHandler class implementation
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * Copyright (C) 2010 Oracle Corporation
|
---|
| 10 | *
|
---|
| 11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
| 14 | * General Public License (GPL) as published by the Free Software
|
---|
| 15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 | /* Local includes */
|
---|
| 21 | #include "UIConsoleEventHandler.h"
|
---|
| 22 | #include "UIMainEventListener.h"
|
---|
| 23 | #include "VBoxGlobal.h"
|
---|
| 24 | #include "UISession.h"
|
---|
| 25 |
|
---|
| 26 | #ifdef Q_WS_MAC
|
---|
| 27 | # include "VBoxUtils.h"
|
---|
| 28 | #endif /* Q_WS_MAC */
|
---|
| 29 |
|
---|
| 30 | /* Global includes */
|
---|
| 31 | //#include <iprt/thread.h>
|
---|
| 32 | //#include <iprt/stream.h>
|
---|
| 33 |
|
---|
| 34 | /* static */
|
---|
| 35 | UIConsoleEventHandler *UIConsoleEventHandler::m_pInstance = 0;
|
---|
| 36 |
|
---|
| 37 | /* static */
|
---|
| 38 | UIConsoleEventHandler* UIConsoleEventHandler::instance(UISession *pSession /* = 0 */)
|
---|
| 39 | {
|
---|
| 40 | if (!m_pInstance)
|
---|
| 41 | m_pInstance = new UIConsoleEventHandler(pSession);
|
---|
| 42 | return m_pInstance;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | /* static */
|
---|
| 46 | void UIConsoleEventHandler::destroy()
|
---|
| 47 | {
|
---|
[30703] | 48 | if (m_pInstance)
|
---|
[30677] | 49 | {
|
---|
| 50 | delete m_pInstance;
|
---|
| 51 | m_pInstance = 0;
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession)
|
---|
| 56 | : m_pSession(pSession)
|
---|
| 57 | {
|
---|
| 58 | Assert(pSession);
|
---|
| 59 |
|
---|
| 60 | // RTPrintf("Self add: %RTthrd\n", RTThreadSelf());
|
---|
[35722] | 61 | ComObjPtr<UIMainEventListenerImpl> pListener;
|
---|
| 62 | pListener.createObject();
|
---|
| 63 | pListener->init(new UIMainEventListener(), this);
|
---|
[30677] | 64 | m_mainEventListener = CEventListener(pListener);
|
---|
| 65 | QVector<KVBoxEventType> events;
|
---|
| 66 | events
|
---|
[30871] | 67 | << KVBoxEventType_OnMousePointerShapeChanged
|
---|
| 68 | << KVBoxEventType_OnMouseCapabilityChanged
|
---|
| 69 | << KVBoxEventType_OnKeyboardLedsChanged
|
---|
| 70 | << KVBoxEventType_OnStateChanged
|
---|
| 71 | << KVBoxEventType_OnAdditionsStateChanged
|
---|
| 72 | << KVBoxEventType_OnNetworkAdapterChanged
|
---|
| 73 | << KVBoxEventType_OnMediumChanged
|
---|
| 74 | << KVBoxEventType_OnUSBControllerChanged
|
---|
| 75 | << KVBoxEventType_OnUSBDeviceStateChanged
|
---|
| 76 | << KVBoxEventType_OnSharedFolderChanged
|
---|
[30677] | 77 | << KVBoxEventType_OnRuntimeError
|
---|
| 78 | << KVBoxEventType_OnCanShowWindow
|
---|
| 79 | << KVBoxEventType_OnShowWindow;
|
---|
| 80 |
|
---|
| 81 | const CConsole &console = m_pSession->session().GetConsole();
|
---|
| 82 | console.GetEventSource().RegisterListener(m_mainEventListener, events, TRUE);
|
---|
| 83 | AssertWrapperOk(console);
|
---|
| 84 |
|
---|
[34527] | 85 | connect(pListener->getWrapped(), SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
|
---|
[30677] | 86 | this, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)),
|
---|
| 87 | Qt::QueuedConnection);
|
---|
| 88 |
|
---|
[34527] | 89 | connect(pListener->getWrapped(), SIGNAL(sigMouseCapabilityChange(bool, bool, bool)),
|
---|
[30677] | 90 | this, SIGNAL(sigMouseCapabilityChange(bool, bool, bool)),
|
---|
| 91 | Qt::QueuedConnection);
|
---|
| 92 |
|
---|
[34527] | 93 | connect(pListener->getWrapped(), SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
|
---|
[30677] | 94 | this, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)),
|
---|
| 95 | Qt::QueuedConnection);
|
---|
| 96 |
|
---|
[34527] | 97 | connect(pListener->getWrapped(), SIGNAL(sigStateChange(KMachineState)),
|
---|
[30677] | 98 | this, SIGNAL(sigStateChange(KMachineState)),
|
---|
| 99 | Qt::QueuedConnection);
|
---|
| 100 |
|
---|
[34527] | 101 | connect(pListener->getWrapped(), SIGNAL(sigAdditionsChange()),
|
---|
[30677] | 102 | this, SIGNAL(sigAdditionsChange()),
|
---|
| 103 | Qt::QueuedConnection);
|
---|
| 104 |
|
---|
[34527] | 105 | connect(pListener->getWrapped(), SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
|
---|
[30677] | 106 | this, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)),
|
---|
| 107 | Qt::QueuedConnection);
|
---|
| 108 |
|
---|
[34527] | 109 | connect(pListener->getWrapped(), SIGNAL(sigMediumChange(CMediumAttachment)),
|
---|
[30677] | 110 | this, SIGNAL(sigMediumChange(CMediumAttachment)),
|
---|
| 111 | Qt::QueuedConnection);
|
---|
| 112 |
|
---|
[34527] | 113 | connect(pListener->getWrapped(), SIGNAL(sigUSBControllerChange()),
|
---|
[30677] | 114 | this, SIGNAL(sigUSBControllerChange()),
|
---|
| 115 | Qt::QueuedConnection);
|
---|
| 116 |
|
---|
[34527] | 117 | connect(pListener->getWrapped(), SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
|
---|
[30677] | 118 | this, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)),
|
---|
| 119 | Qt::QueuedConnection);
|
---|
| 120 |
|
---|
[34527] | 121 | connect(pListener->getWrapped(), SIGNAL(sigSharedFolderChange()),
|
---|
[30679] | 122 | this, SIGNAL(sigSharedFolderChange()),
|
---|
[30677] | 123 | Qt::QueuedConnection);
|
---|
| 124 |
|
---|
[34527] | 125 | connect(pListener->getWrapped(), SIGNAL(sigRuntimeError(bool, QString, QString)),
|
---|
[30677] | 126 | this, SIGNAL(sigRuntimeError(bool, QString, QString)),
|
---|
| 127 | Qt::QueuedConnection);
|
---|
| 128 |
|
---|
| 129 | /* This is a vetoable event, so we have to respond to the event and have to
|
---|
| 130 | * use a direct connection therefor. */
|
---|
[34527] | 131 | connect(pListener->getWrapped(), SIGNAL(sigCanShowWindow(bool&, QString&)),
|
---|
[30677] | 132 | this, SLOT(sltCanShowWindow(bool&, QString&)),
|
---|
| 133 | Qt::DirectConnection);
|
---|
| 134 |
|
---|
| 135 | /* This returns a winId, so we have to respond to the event and have to use
|
---|
| 136 | * a direct connection therefor. */
|
---|
[34527] | 137 | connect(pListener->getWrapped(), SIGNAL(sigShowWindow(LONG64&)),
|
---|
[31816] | 138 | this, SLOT(sltShowWindow(LONG64&)),
|
---|
[30677] | 139 | Qt::DirectConnection);
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | UIConsoleEventHandler::~UIConsoleEventHandler()
|
---|
| 143 | {
|
---|
| 144 | const CConsole &console = m_pSession->session().GetConsole();
|
---|
| 145 | console.GetEventSource().UnregisterListener(m_mainEventListener);
|
---|
| 146 | AssertWrapperOk(console);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | void UIConsoleEventHandler::sltCanShowWindow(bool & /* fVeto */, QString & /* strReason */)
|
---|
| 150 | {
|
---|
| 151 | /* No veto, so nothing for us to do. */
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[31816] | 154 | void UIConsoleEventHandler::sltShowWindow(LONG64 &winId)
|
---|
[30677] | 155 | {
|
---|
| 156 | #ifdef Q_WS_MAC
|
---|
| 157 | /* Let's try the simple approach first - grab the focus.
|
---|
| 158 | * Getting a window out of the dock (minimized or whatever it's called)
|
---|
| 159 | * needs to be done on the GUI thread, so post it a note: */
|
---|
| 160 | winId = 0;
|
---|
| 161 | if (::darwinSetFrontMostProcess())
|
---|
| 162 | emit sigShowWindow();
|
---|
| 163 | else
|
---|
| 164 | {
|
---|
| 165 | /* It failed for some reason, send the other process our PSN so it can try.
|
---|
| 166 | * (This is just a precaution should Mac OS X start imposing the same sensible
|
---|
| 167 | * focus stealing restrictions that other window managers implement). */
|
---|
| 168 | winId = ::darwinGetCurrentProcessId();
|
---|
| 169 | }
|
---|
| 170 | #else /* Q_WS_MAC */
|
---|
| 171 | /* Return the ID of the top-level console window. */
|
---|
| 172 | winId = (ULONG64)m_pSession->winId();
|
---|
| 173 | #endif /* !Q_WS_MAC */
|
---|
| 174 | }
|
---|
| 175 |
|
---|