VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIConsoleEventHandler.cpp@ 100064

Last change on this file since 100064 was 98382, checked in by vboxsync, 17 months ago

Merging r155235 and r155243 from gui4 branch: FE/Qt: Runtime UI: Small cleanup in UISession code related to action-pool, additions stuff and UIConsoleEventHandler.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.2 KB
Line 
1/* $Id: UIConsoleEventHandler.cpp 98382 2023-02-01 12:59:50Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIConsoleEventHandler class implementation.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* GUI includes: */
29#include "UICommon.h"
30#include "UIConsoleEventHandler.h"
31#include "UIExtraDataManager.h"
32#include "UIMainEventListener.h"
33#include "UIMousePointerShapeData.h"
34#include "UISession.h"
35#ifdef VBOX_WS_MAC
36# include "VBoxUtils.h"
37#endif
38
39/* COM includes: */
40#include "COMEnums.h"
41#include "CConsole.h"
42#include "CEventListener.h"
43#include "CEventSource.h"
44
45
46/** Private QObject subclass
47 * providing UIConsoleEventHandler with the CConsole event-source. */
48class UIConsoleEventHandlerProxy : public QObject
49{
50 Q_OBJECT;
51
52signals:
53
54 /** Notifies about mouse pointer @a shapeData change. */
55 void sigMousePointerShapeChange(const UIMousePointerShapeData &shapeData);
56 /** Notifies about mouse capability change to @a fSupportsAbsolute, @a fSupportsRelative,
57 * @a fSupportsTouchScreen, @a fSupportsTouchPad, and @a fNeedsHostCursor. */
58 void sigMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative,
59 bool fSupportsTouchScreen, bool fSupportsTouchPad,
60 bool fNeedsHostCursor);
61 /** Notifies about guest request to change the cursor position to @a uX * @a uY.
62 * @param fContainsData Brings whether the @a uX and @a uY values are valid and could be used by the GUI now. */
63 void sigCursorPositionChange(bool fContainsData, unsigned long uX, unsigned long uY);
64 /** Notifies about keyboard LEDs change for @a fNumLock, @a fCapsLock and @a fScrollLock. */
65 void sigKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
66 /** Notifies about machine @a state change. */
67 void sigStateChange(KMachineState state);
68 /** Notifies about guest additions state change. */
69 void sigAdditionsChange();
70 /** Notifies about network @a adapter state change. */
71 void sigNetworkAdapterChange(CNetworkAdapter adapter);
72 /** Notifies about storage device change for @a attachment, which was @a fRemoved and it was @a fSilent for guest. */
73 void sigStorageDeviceChange(CMediumAttachment attachment, bool fRemoved, bool fSilent);
74 /** Notifies about storage medium @a attachment state change. */
75 void sigMediumChange(CMediumAttachment attachment);
76 /** Notifies about VRDE device state change. */
77 void sigVRDEChange();
78 /** Notifies about recording state change. */
79 void sigRecordingChange();
80 /** Notifies about USB controller state change. */
81 void sigUSBControllerChange();
82 /** Notifies about USB @a device state change to @a fAttached, holding additional @a error information. */
83 void sigUSBDeviceStateChange(CUSBDevice device, bool fAttached, CVirtualBoxErrorInfo error);
84 /** Notifies about shared folder state change. */
85 void sigSharedFolderChange();
86 /** Notifies about CPU execution-cap change. */
87 void sigCPUExecutionCapChange();
88 /** Notifies about guest-screen configuration change of @a type for @a uScreenId with @a screenGeo. */
89 void sigGuestMonitorChange(KGuestMonitorChangedEventType type, ulong uScreenId, QRect screenGeo);
90 /** Notifies about Runtime error with @a strErrorId which is @a fFatal and have @a strMessage. */
91 void sigRuntimeError(bool fFatal, QString strErrorId, QString strMessage);
92#ifdef VBOX_WS_MAC
93 /** Notifies about VM window should be shown. */
94 void sigShowWindow();
95#endif /* VBOX_WS_MAC */
96 /** Notifies about audio adapter state change. */
97 void sigAudioAdapterChange();
98 /** Notifies clipboard mode change. */
99 void sigClipboardModeChange(KClipboardMode enmMode);
100 /** Notifies drag and drop mode change. */
101 void sigDnDModeChange(KDnDMode enmMode);
102
103public:
104
105 /** Constructs event proxy object on the basis of passed @a pParent and @a pSession. */
106 UIConsoleEventHandlerProxy(QObject *pParent, UISession *pSession);
107 /** Destructs event proxy object. */
108 virtual ~UIConsoleEventHandlerProxy() RT_OVERRIDE;
109
110private slots:
111
112 /** Returns whether VM window can be shown. */
113 void sltCanShowWindow(bool &fVeto, QString &strReason);
114 /** Shows VM window if possible. */
115 void sltShowWindow(qint64 &winId);
116
117private:
118
119 /** Prepares all. */
120 void prepare();
121 /** Prepares listener. */
122 void prepareListener();
123 /** Prepares connections. */
124 void prepareConnections();
125
126 /** Cleanups connections. */
127 void cleanupConnections() {}
128 /** Cleanups listener. */
129 void cleanupListener();
130 /** Cleanups all. */
131 void cleanup();
132
133 /** Holds the UI session reference. */
134 UISession *m_pSession;
135
136 /** Holds the Qt event listener instance. */
137 ComObjPtr<UIMainEventListenerImpl> m_pQtListener;
138 /** Holds the COM event listener instance. */
139 CEventListener m_comEventListener;
140};
141
142
143/*********************************************************************************************************************************
144* Class UIConsoleEventHandlerProxy implementation. *
145*********************************************************************************************************************************/
146
147UIConsoleEventHandlerProxy::UIConsoleEventHandlerProxy(QObject *pParent, UISession *pSession)
148 : QObject(pParent)
149 , m_pSession(pSession)
150{
151 prepare();
152}
153
154UIConsoleEventHandlerProxy::~UIConsoleEventHandlerProxy()
155{
156 cleanup();
157}
158
159void UIConsoleEventHandlerProxy::sltCanShowWindow(bool & /* fVeto */, QString & /* strReason */)
160{
161 /* Nothing for now. */
162}
163
164void UIConsoleEventHandlerProxy::sltShowWindow(qint64 &winId)
165{
166#ifdef VBOX_WS_MAC
167 /* First of all, just ask the GUI thread to show the machine-window: */
168 winId = 0;
169 if (::darwinSetFrontMostProcess())
170 emit sigShowWindow();
171 else
172 {
173 /* If it's failed for some reason, send the other process our PSN so it can try: */
174 winId = ::darwinGetCurrentProcessId();
175 }
176#else /* !VBOX_WS_MAC */
177 /* Return the ID of the top-level machine-window. */
178 winId = (ULONG64)m_pSession->mainMachineWindowId();
179#endif /* !VBOX_WS_MAC */
180}
181
182void UIConsoleEventHandlerProxy::prepare()
183{
184 prepareListener();
185 prepareConnections();
186}
187
188void UIConsoleEventHandlerProxy::prepareListener()
189{
190 /* Make sure session is passed: */
191 AssertPtrReturnVoid(m_pSession);
192
193 /* Create event listener instance: */
194 m_pQtListener.createObject();
195 m_pQtListener->init(new UIMainEventListener, this);
196 m_comEventListener = CEventListener(m_pQtListener);
197
198 /* Get console: */
199 const CConsole comConsole = m_pSession->session().GetConsole();
200 AssertReturnVoid(!comConsole.isNull() && comConsole.isOk());
201 /* Get console event source: */
202 CEventSource comEventSourceConsole = comConsole.GetEventSource();
203 AssertReturnVoid(!comEventSourceConsole.isNull() && comEventSourceConsole.isOk());
204
205 /* Enumerate all the required event-types: */
206 QVector<KVBoxEventType> eventTypes;
207 eventTypes
208 << KVBoxEventType_OnMousePointerShapeChanged
209 << KVBoxEventType_OnMouseCapabilityChanged
210 << KVBoxEventType_OnCursorPositionChanged
211 << KVBoxEventType_OnKeyboardLedsChanged
212 << KVBoxEventType_OnStateChanged
213 << KVBoxEventType_OnAdditionsStateChanged
214 << KVBoxEventType_OnNetworkAdapterChanged
215 << KVBoxEventType_OnStorageDeviceChanged
216 << KVBoxEventType_OnMediumChanged
217 << KVBoxEventType_OnVRDEServerChanged
218 << KVBoxEventType_OnVRDEServerInfoChanged
219 << KVBoxEventType_OnRecordingChanged
220 << KVBoxEventType_OnUSBControllerChanged
221 << KVBoxEventType_OnUSBDeviceStateChanged
222 << KVBoxEventType_OnSharedFolderChanged
223 << KVBoxEventType_OnCPUExecutionCapChanged
224 << KVBoxEventType_OnGuestMonitorChanged
225 << KVBoxEventType_OnRuntimeError
226 << KVBoxEventType_OnCanShowWindow
227 << KVBoxEventType_OnShowWindow
228 << KVBoxEventType_OnAudioAdapterChanged
229 << KVBoxEventType_OnClipboardModeChanged
230 << KVBoxEventType_OnDnDModeChanged
231 ;
232
233 /* Register event listener for console event source: */
234 comEventSourceConsole.RegisterListener(m_comEventListener, eventTypes, FALSE /* active? */);
235 AssertWrapperOk(comEventSourceConsole);
236
237 /* Register event sources in their listeners as well: */
238 m_pQtListener->getWrapped()->registerSource(comEventSourceConsole, m_comEventListener);
239}
240
241void UIConsoleEventHandlerProxy::prepareConnections()
242{
243 /* Create direct (sync) connections for signals of main listener: */
244 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigMousePointerShapeChange,
245 this, &UIConsoleEventHandlerProxy::sigMousePointerShapeChange,
246 Qt::DirectConnection);
247 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigMouseCapabilityChange,
248 this, &UIConsoleEventHandlerProxy::sigMouseCapabilityChange,
249 Qt::DirectConnection);
250 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigCursorPositionChange,
251 this, &UIConsoleEventHandlerProxy::sigCursorPositionChange,
252 Qt::DirectConnection);
253 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigKeyboardLedsChange,
254 this, &UIConsoleEventHandlerProxy::sigKeyboardLedsChange,
255 Qt::DirectConnection);
256 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigStateChange,
257 this, &UIConsoleEventHandlerProxy::sigStateChange,
258 Qt::DirectConnection);
259 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigAdditionsChange,
260 this, &UIConsoleEventHandlerProxy::sigAdditionsChange,
261 Qt::DirectConnection);
262 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigNetworkAdapterChange,
263 this, &UIConsoleEventHandlerProxy::sigNetworkAdapterChange,
264 Qt::DirectConnection);
265 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigStorageDeviceChange,
266 this, &UIConsoleEventHandlerProxy::sigStorageDeviceChange,
267 Qt::DirectConnection);
268 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigMediumChange,
269 this, &UIConsoleEventHandlerProxy::sigMediumChange,
270 Qt::DirectConnection);
271 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigVRDEChange,
272 this, &UIConsoleEventHandlerProxy::sigVRDEChange,
273 Qt::DirectConnection);
274 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigRecordingChange,
275 this, &UIConsoleEventHandlerProxy::sigRecordingChange,
276 Qt::DirectConnection);
277 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigUSBControllerChange,
278 this, &UIConsoleEventHandlerProxy::sigUSBControllerChange,
279 Qt::DirectConnection);
280 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigUSBDeviceStateChange,
281 this, &UIConsoleEventHandlerProxy::sigUSBDeviceStateChange,
282 Qt::DirectConnection);
283 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigSharedFolderChange,
284 this, &UIConsoleEventHandlerProxy::sigSharedFolderChange,
285 Qt::DirectConnection);
286 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigCPUExecutionCapChange,
287 this, &UIConsoleEventHandlerProxy::sigCPUExecutionCapChange,
288 Qt::DirectConnection);
289 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestMonitorChange,
290 this, &UIConsoleEventHandlerProxy::sigGuestMonitorChange,
291 Qt::DirectConnection);
292 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigRuntimeError,
293 this, &UIConsoleEventHandlerProxy::sigRuntimeError,
294 Qt::DirectConnection);
295 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigCanShowWindow,
296 this, &UIConsoleEventHandlerProxy::sltCanShowWindow,
297 Qt::DirectConnection);
298 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigShowWindow,
299 this, &UIConsoleEventHandlerProxy::sltShowWindow,
300 Qt::DirectConnection);
301 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigAudioAdapterChange,
302 this, &UIConsoleEventHandlerProxy::sigAudioAdapterChange,
303 Qt::DirectConnection);
304 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigClipboardModeChange,
305 this, &UIConsoleEventHandlerProxy::sigClipboardModeChange,
306 Qt::DirectConnection);
307 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigDnDModeChange,
308 this, &UIConsoleEventHandlerProxy::sigDnDModeChange,
309 Qt::DirectConnection);
310}
311
312void UIConsoleEventHandlerProxy::cleanupListener()
313{
314 /* Make sure session is passed: */
315 AssertPtrReturnVoid(m_pSession);
316
317 /* Unregister everything: */
318 m_pQtListener->getWrapped()->unregisterSources();
319
320 /* Get console: */
321 const CConsole comConsole = m_pSession->session().GetConsole();
322 if (comConsole.isNull() || !comConsole.isOk())
323 return;
324 /* Get console event source: */
325 CEventSource comEventSourceConsole = comConsole.GetEventSource();
326 AssertWrapperOk(comEventSourceConsole);
327
328 /* Unregister event listener for console event source: */
329 comEventSourceConsole.UnregisterListener(m_comEventListener);
330}
331
332void UIConsoleEventHandlerProxy::cleanup()
333{
334 cleanupConnections();
335 cleanupListener();
336}
337
338
339/*********************************************************************************************************************************
340* Class UIConsoleEventHandler implementation. *
341*********************************************************************************************************************************/
342
343UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession)
344 : m_pProxy(new UIConsoleEventHandlerProxy(this, pSession))
345{
346 prepare();
347}
348
349void UIConsoleEventHandler::prepare()
350{
351 /* Create queued (async) connections for signals of event proxy object: */
352 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigMousePointerShapeChange,
353 this, &UIConsoleEventHandler::sigMousePointerShapeChange,
354 Qt::QueuedConnection);
355 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigMouseCapabilityChange,
356 this, &UIConsoleEventHandler::sigMouseCapabilityChange,
357 Qt::QueuedConnection);
358 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigCursorPositionChange,
359 this, &UIConsoleEventHandler::sigCursorPositionChange,
360 Qt::QueuedConnection);
361 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigKeyboardLedsChange,
362 this, &UIConsoleEventHandler::sigKeyboardLedsChange,
363 Qt::QueuedConnection);
364 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigStateChange,
365 this, &UIConsoleEventHandler::sigStateChange,
366 Qt::QueuedConnection);
367 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigAdditionsChange,
368 this, &UIConsoleEventHandler::sigAdditionsChange,
369 Qt::QueuedConnection);
370 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigNetworkAdapterChange,
371 this, &UIConsoleEventHandler::sigNetworkAdapterChange,
372 Qt::QueuedConnection);
373 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigStorageDeviceChange,
374 this, &UIConsoleEventHandler::sigStorageDeviceChange,
375 Qt::QueuedConnection);
376 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigMediumChange,
377 this, &UIConsoleEventHandler::sigMediumChange,
378 Qt::QueuedConnection);
379 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigVRDEChange,
380 this, &UIConsoleEventHandler::sigVRDEChange,
381 Qt::QueuedConnection);
382 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigRecordingChange,
383 this, &UIConsoleEventHandler::sigRecordingChange,
384 Qt::QueuedConnection);
385 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigUSBControllerChange,
386 this, &UIConsoleEventHandler::sigUSBControllerChange,
387 Qt::QueuedConnection);
388 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigUSBDeviceStateChange,
389 this, &UIConsoleEventHandler::sigUSBDeviceStateChange,
390 Qt::QueuedConnection);
391 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigSharedFolderChange,
392 this, &UIConsoleEventHandler::sigSharedFolderChange,
393 Qt::QueuedConnection);
394 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigCPUExecutionCapChange,
395 this, &UIConsoleEventHandler::sigCPUExecutionCapChange,
396 Qt::QueuedConnection);
397 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigGuestMonitorChange,
398 this, &UIConsoleEventHandler::sigGuestMonitorChange,
399 Qt::QueuedConnection);
400 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigRuntimeError,
401 this, &UIConsoleEventHandler::sigRuntimeError,
402 Qt::QueuedConnection);
403#ifdef VBOX_WS_MAC
404 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigShowWindow,
405 this, &UIConsoleEventHandler::sigShowWindow,
406 Qt::QueuedConnection);
407#endif /* VBOX_WS_MAC */
408 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigAudioAdapterChange,
409 this, &UIConsoleEventHandler::sigAudioAdapterChange,
410 Qt::QueuedConnection);
411 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigClipboardModeChange,
412 this, &UIConsoleEventHandler::sigClipboardModeChange,
413 Qt::QueuedConnection);
414 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigDnDModeChange,
415 this, &UIConsoleEventHandler::sigDnDModeChange,
416 Qt::QueuedConnection);
417}
418
419#include "UIConsoleEventHandler.moc"
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use