UIVirtualBoxEventHandler::UIVirtualBoxEventHandler() { // RTPrintf("Self add: %RTthrd\n", RTThreadSelf()); const CVirtualBox &vbox = vboxGlobal().virtualBox(); ComObjPtr<UIMainEventListenerImpl> pListener; pListener.createObject(); pListener->init(new UIMainEventListener(), this); m_mainEventListener = CEventListener(pListener); QVector<KVBoxEventType> events; events << KVBoxEventType_OnMachineStateChanged << KVBoxEventType_OnMachineDataChanged << KVBoxEventType_OnMachineRegistered << KVBoxEventType_OnSessionStateChanged << KVBoxEventType_OnSnapshotTaken << KVBoxEventType_OnSnapshotDeleted << KVBoxEventType_OnSnapshotChanged; vbox.GetEventSource().RegisterListener(m_mainEventListener, events, TRUE); AssertWrapperOk(vbox); connect(pListener->getWrapped(), SIGNAL(sigMachineStateChange(QString, KMachineState)), this, SIGNAL(sigMachineStateChange(QString, KMachineState)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigMachineDataChange(QString)), this, SIGNAL(sigMachineDataChange(QString)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigMachineRegistered(QString, bool)), this, SIGNAL(sigMachineRegistered(QString, bool)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigSessionStateChange(QString, KSessionState)), this, SIGNAL(sigSessionStateChange(QString, KSessionState)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigSnapshotChange(QString, QString)), this, SIGNAL(sigSnapshotChange(QString, QString)), Qt::QueuedConnection); }
/** * Tries to switch to the main window of the VM process. * * @return true if successfully switched and false otherwise. */ bool UIVMItem::switchTo() { #ifdef VBOX_WS_MAC ULONG64 id = m_machine.ShowConsoleWindow(); #else WId id = (WId) m_machine.ShowConsoleWindow(); #endif AssertWrapperOk(m_machine); if (!m_machine.isOk()) return false; /* winId = 0 it means the console window has already done everything * necessary to implement the "show window" semantics. */ if (id == 0) return true; #if defined (VBOX_WS_WIN) || defined (VBOX_WS_X11) return vboxGlobal().activateWindow(id, true); #elif defined (VBOX_WS_MAC) /* * This is just for the case were the other process cannot steal * the focus from us. It will send us a PSN so we can try. */ ProcessSerialNumber psn; psn.highLongOfPSN = id >> 32; psn.lowLongOfPSN = (UInt32)id; OSErr rc = ::SetFrontProcess(&psn); if (!rc) Log(("GUI: %#RX64 couldn't do SetFrontProcess on itself, the selector (we) had to do it...\n", id)); else Log(("GUI: Failed to bring %#RX64 to front. rc=%#x\n", id, rc)); return !rc; #endif return false; /// @todo Below is the old method of switching to the console window // based on the process ID of the console process. It should go away // after the new (callback-based) method is fully tested. #if 0 if (!canSwitchTo()) return false; #if defined (VBOX_WS_WIN) HWND hwnd = mWinId; /* if there are blockers (modal and modeless dialogs, etc), find the * topmost one */ HWND hwndAbove = NULL; do { hwndAbove = GetNextWindow(hwnd, GW_HWNDPREV); HWND hwndOwner; if (hwndAbove != NULL && ((hwndOwner = GetWindow(hwndAbove, GW_OWNER)) == hwnd || hwndOwner == hwndAbove)) hwnd = hwndAbove; else break; } while (1); /* first, check that the primary window is visible */ if (IsIconic(mWinId)) ShowWindow(mWinId, SW_RESTORE); else if (!IsWindowVisible(mWinId)) ShowWindow(mWinId, SW_SHOW); #if 0 LogFlowFunc(("mWinId=%08X hwnd=%08X\n", mWinId, hwnd)); #endif /* then, activate the topmost in the group */ AllowSetForegroundWindow(m_pid); SetForegroundWindow(hwnd); return true; #elif defined (VBOX_WS_X11) return false; #elif defined (VBOX_WS_MAC) ProcessSerialNumber psn; OSStatus rc = ::GetProcessForPID(m_pid, &psn); if (!rc) { rc = ::SetFrontProcess(&psn); if (!rc) { ShowHideProcess(&psn, true); return true; } } return false; #else return false; #endif #endif }
UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession) : m_pSession(pSession) { Assert(pSession); // RTPrintf("Self add: %RTthrd\n", RTThreadSelf()); ComObjPtr<UIMainEventListenerImpl> pListener; pListener.createObject(); pListener->init(new UIMainEventListener(), this); m_mainEventListener = CEventListener(pListener); QVector<KVBoxEventType> events; events << KVBoxEventType_OnMousePointerShapeChanged << KVBoxEventType_OnMouseCapabilityChanged << KVBoxEventType_OnKeyboardLedsChanged << KVBoxEventType_OnStateChanged << KVBoxEventType_OnAdditionsStateChanged << KVBoxEventType_OnNetworkAdapterChanged << KVBoxEventType_OnMediumChanged << KVBoxEventType_OnVRDEServerChanged << KVBoxEventType_OnVRDEServerInfoChanged << KVBoxEventType_OnUSBControllerChanged << KVBoxEventType_OnUSBDeviceStateChanged << KVBoxEventType_OnSharedFolderChanged << KVBoxEventType_OnRuntimeError << KVBoxEventType_OnCanShowWindow << KVBoxEventType_OnShowWindow << KVBoxEventType_OnCPUExecutionCapChanged << KVBoxEventType_OnGuestMonitorChanged; const CConsole &console = m_pSession->session().GetConsole(); console.GetEventSource().RegisterListener(m_mainEventListener, events, TRUE); AssertWrapperOk(console); connect(pListener->getWrapped(), SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)), this, SIGNAL(sigMousePointerShapeChange(bool, bool, QPoint, QSize, QVector<uint8_t>)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigMouseCapabilityChange(bool, bool, bool)), this, SIGNAL(sigMouseCapabilityChange(bool, bool, bool)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)), this, SIGNAL(sigKeyboardLedsChangeEvent(bool, bool, bool)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigStateChange(KMachineState)), this, SIGNAL(sigStateChange(KMachineState)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigAdditionsChange()), this, SIGNAL(sigAdditionsChange()), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)), this, SIGNAL(sigNetworkAdapterChange(CNetworkAdapter)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigMediumChange(CMediumAttachment)), this, SIGNAL(sigMediumChange(CMediumAttachment)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigVRDEChange()), this, SIGNAL(sigVRDEChange()), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigUSBControllerChange()), this, SIGNAL(sigUSBControllerChange()), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)), this, SIGNAL(sigUSBDeviceStateChange(CUSBDevice, bool, CVirtualBoxErrorInfo)), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigSharedFolderChange()), this, SIGNAL(sigSharedFolderChange()), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigRuntimeError(bool, QString, QString)), this, SIGNAL(sigRuntimeError(bool, QString, QString)), Qt::QueuedConnection); /* This is a vetoable event, so we have to respond to the event and have to * use a direct connection therefor. */ connect(pListener->getWrapped(), SIGNAL(sigCanShowWindow(bool&, QString&)), this, SLOT(sltCanShowWindow(bool&, QString&)), Qt::DirectConnection); /* This returns a winId, so we have to respond to the event and have to use * a direct connection therefor. */ connect(pListener->getWrapped(), SIGNAL(sigShowWindow(LONG64&)), this, SLOT(sltShowWindow(LONG64&)), Qt::DirectConnection); connect(pListener->getWrapped(), SIGNAL(sigCPUExecutionCapChange()), this, SIGNAL(sigCPUExecutionCapChange()), Qt::QueuedConnection); connect(pListener->getWrapped(), SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)), this, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)), Qt::QueuedConnection); }
UIConsoleEventHandler::~UIConsoleEventHandler() { const CConsole &console = m_pSession->session().GetConsole(); console.GetEventSource().UnregisterListener(m_mainEventListener); AssertWrapperOk(console); }