VirtualBox

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

Last change on this file was 103803, checked in by vboxsync, 2 months ago

FE/Qt. bugref:10618. Splitting COMEnums.h file into individual enum header files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.7 KB
Line 
1/* $Id: UIConsoleEventHandler.cpp 103803 2024-03-12 11:15:18Z 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 "UIConsoleEventHandler.h"
30#include "UIExtraDataManager.h"
31#include "UIMainEventListener.h"
32#include "UIMousePointerShapeData.h"
33#include "UISession.h"
34#ifdef VBOX_WS_MAC
35# include "VBoxUtils.h"
36#endif
37
38/* COM includes: */
39#include "CConsole.h"
40#include "CEventListener.h"
41#include "CEventSource.h"
42
43
44/** Private QObject subclass
45 * providing UIConsoleEventHandler with the CConsole event-source. */
46class UIConsoleEventHandlerProxy : public QObject
47{
48 Q_OBJECT;
49
50signals:
51
52 /** Notifies about mouse pointer @a shapeData change. */
53 void sigMousePointerShapeChange(const UIMousePointerShapeData &shapeData);
54 /** Notifies about mouse capability change to @a fSupportsAbsolute, @a fSupportsRelative,
55 * @a fSupportsTouchScreen, @a fSupportsTouchPad, and @a fNeedsHostCursor. */
56 void sigMouseCapabilityChange(bool fSupportsAbsolute, bool fSupportsRelative,
57 bool fSupportsTouchScreen, bool fSupportsTouchPad,
58 bool fNeedsHostCursor);
59 /** Notifies about guest request to change the cursor position to @a uX * @a uY.
60 * @param fContainsData Brings whether the @a uX and @a uY values are valid and could be used by the GUI now. */
61 void sigCursorPositionChange(bool fContainsData, unsigned long uX, unsigned long uY);
62 /** Notifies about keyboard LEDs change for @a fNumLock, @a fCapsLock and @a fScrollLock. */
63 void sigKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
64 /** Notifies about machine @a state change. */
65 void sigStateChange(KMachineState state);
66 /** Notifies about guest additions state change. */
67 void sigAdditionsChange();
68 /** Notifies about network @a adapter state change. */
69 void sigNetworkAdapterChange(CNetworkAdapter adapter);
70 /** Notifies about storage device change for @a attachment, which was @a fRemoved and it was @a fSilent for guest. */
71 void sigStorageDeviceChange(CMediumAttachment attachment, bool fRemoved, bool fSilent);
72 /** Notifies about storage medium @a attachment state change. */
73 void sigMediumChange(CMediumAttachment attachment);
74 /** Notifies about VRDE device state change. */
75 void sigVRDEChange();
76 /** Notifies about recording state change. */
77 void sigRecordingChange();
78 /** Notifies about USB controller state change. */
79 void sigUSBControllerChange();
80 /** Notifies about USB @a device state change to @a fAttached, holding additional @a error information. */
81 void sigUSBDeviceStateChange(CUSBDevice device, bool fAttached, CVirtualBoxErrorInfo error);
82 /** Notifies about shared folder state change. */
83 void sigSharedFolderChange();
84 /** Notifies about CPU execution-cap change. */
85 void sigCPUExecutionCapChange();
86 /** Notifies about guest-screen configuration change of @a type for @a uScreenId with @a screenGeo. */
87 void sigGuestMonitorChange(KGuestMonitorChangedEventType type, ulong uScreenId, QRect screenGeo);
88 /** Notifies about Runtime error with @a strErrorId which is @a fFatal and have @a strMessage. */
89 void sigRuntimeError(bool fFatal, QString strErrorId, QString strMessage);
90#ifdef VBOX_WS_MAC
91 /** Notifies about VM window should be shown. */
92 void sigShowWindow();
93#endif /* VBOX_WS_MAC */
94 /** Notifies about audio adapter state change. */
95 void sigAudioAdapterChange();
96 /** Notifies clipboard mode change. */
97 void sigClipboardModeChange(KClipboardMode enmMode);
98 /** Notifies about a clipboard error. */
99 void sigClipboardError(QString strId, QString strMsg, long rcError);
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_OnClipboardError
231 << KVBoxEventType_OnDnDModeChanged
232 ;
233
234 /* Register event listener for console event source: */
235 comEventSourceConsole.RegisterListener(m_comEventListener, eventTypes, FALSE /* active? */);
236 Assert(comEventSourceConsole.isOk());
237
238 /* Register event sources in their listeners as well: */
239 m_pQtListener->getWrapped()->registerSource(comEventSourceConsole, m_comEventListener);
240}
241
242void UIConsoleEventHandlerProxy::prepareConnections()
243{
244 /* Create direct (sync) connections for signals of main listener: */
245 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigMousePointerShapeChange,
246 this, &UIConsoleEventHandlerProxy::sigMousePointerShapeChange,
247 Qt::DirectConnection);
248 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigMouseCapabilityChange,
249 this, &UIConsoleEventHandlerProxy::sigMouseCapabilityChange,
250 Qt::DirectConnection);
251 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigCursorPositionChange,
252 this, &UIConsoleEventHandlerProxy::sigCursorPositionChange,
253 Qt::DirectConnection);
254 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigKeyboardLedsChange,
255 this, &UIConsoleEventHandlerProxy::sigKeyboardLedsChange,
256 Qt::DirectConnection);
257 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigStateChange,
258 this, &UIConsoleEventHandlerProxy::sigStateChange,
259 Qt::DirectConnection);
260 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigAdditionsChange,
261 this, &UIConsoleEventHandlerProxy::sigAdditionsChange,
262 Qt::DirectConnection);
263 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigNetworkAdapterChange,
264 this, &UIConsoleEventHandlerProxy::sigNetworkAdapterChange,
265 Qt::DirectConnection);
266 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigStorageDeviceChange,
267 this, &UIConsoleEventHandlerProxy::sigStorageDeviceChange,
268 Qt::DirectConnection);
269 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigMediumChange,
270 this, &UIConsoleEventHandlerProxy::sigMediumChange,
271 Qt::DirectConnection);
272 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigVRDEChange,
273 this, &UIConsoleEventHandlerProxy::sigVRDEChange,
274 Qt::DirectConnection);
275 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigRecordingChange,
276 this, &UIConsoleEventHandlerProxy::sigRecordingChange,
277 Qt::DirectConnection);
278 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigUSBControllerChange,
279 this, &UIConsoleEventHandlerProxy::sigUSBControllerChange,
280 Qt::DirectConnection);
281 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigUSBDeviceStateChange,
282 this, &UIConsoleEventHandlerProxy::sigUSBDeviceStateChange,
283 Qt::DirectConnection);
284 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigSharedFolderChange,
285 this, &UIConsoleEventHandlerProxy::sigSharedFolderChange,
286 Qt::DirectConnection);
287 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigCPUExecutionCapChange,
288 this, &UIConsoleEventHandlerProxy::sigCPUExecutionCapChange,
289 Qt::DirectConnection);
290 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigGuestMonitorChange,
291 this, &UIConsoleEventHandlerProxy::sigGuestMonitorChange,
292 Qt::DirectConnection);
293 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigRuntimeError,
294 this, &UIConsoleEventHandlerProxy::sigRuntimeError,
295 Qt::DirectConnection);
296 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigCanShowWindow,
297 this, &UIConsoleEventHandlerProxy::sltCanShowWindow,
298 Qt::DirectConnection);
299 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigShowWindow,
300 this, &UIConsoleEventHandlerProxy::sltShowWindow,
301 Qt::DirectConnection);
302 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigAudioAdapterChange,
303 this, &UIConsoleEventHandlerProxy::sigAudioAdapterChange,
304 Qt::DirectConnection);
305 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigClipboardModeChange,
306 this, &UIConsoleEventHandlerProxy::sigClipboardModeChange,
307 Qt::DirectConnection);
308 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigClipboardError,
309 this, &UIConsoleEventHandlerProxy::sigClipboardError,
310 Qt::DirectConnection);
311 connect(m_pQtListener->getWrapped(), &UIMainEventListener::sigDnDModeChange,
312 this, &UIConsoleEventHandlerProxy::sigDnDModeChange,
313 Qt::DirectConnection);
314}
315
316void UIConsoleEventHandlerProxy::cleanupListener()
317{
318 /* Make sure session is passed: */
319 AssertPtrReturnVoid(m_pSession);
320
321 /* Unregister everything: */
322 m_pQtListener->getWrapped()->unregisterSources();
323
324 /* Get console: */
325 const CConsole comConsole = m_pSession->session().GetConsole();
326 if (comConsole.isNull() || !comConsole.isOk())
327 return;
328 /* Get console event source: */
329 CEventSource comEventSourceConsole = comConsole.GetEventSource();
330 Assert(comConsole.isOk());
331
332 /* Unregister event listener for console event source: */
333 comEventSourceConsole.UnregisterListener(m_comEventListener);
334}
335
336void UIConsoleEventHandlerProxy::cleanup()
337{
338 cleanupConnections();
339 cleanupListener();
340}
341
342
343/*********************************************************************************************************************************
344* Class UIConsoleEventHandler implementation. *
345*********************************************************************************************************************************/
346
347UIConsoleEventHandler::UIConsoleEventHandler(UISession *pSession)
348 : m_pProxy(new UIConsoleEventHandlerProxy(this, pSession))
349{
350 prepare();
351}
352
353void UIConsoleEventHandler::prepare()
354{
355 /* Create queued (async) connections for signals of event proxy object: */
356 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigMousePointerShapeChange,
357 this, &UIConsoleEventHandler::sigMousePointerShapeChange,
358 Qt::QueuedConnection);
359 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigMouseCapabilityChange,
360 this, &UIConsoleEventHandler::sigMouseCapabilityChange,
361 Qt::QueuedConnection);
362 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigCursorPositionChange,
363 this, &UIConsoleEventHandler::sigCursorPositionChange,
364 Qt::QueuedConnection);
365 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigKeyboardLedsChange,
366 this, &UIConsoleEventHandler::sigKeyboardLedsChange,
367 Qt::QueuedConnection);
368 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigStateChange,
369 this, &UIConsoleEventHandler::sigStateChange,
370 Qt::QueuedConnection);
371 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigAdditionsChange,
372 this, &UIConsoleEventHandler::sigAdditionsChange,
373 Qt::QueuedConnection);
374 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigNetworkAdapterChange,
375 this, &UIConsoleEventHandler::sigNetworkAdapterChange,
376 Qt::QueuedConnection);
377 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigStorageDeviceChange,
378 this, &UIConsoleEventHandler::sigStorageDeviceChange,
379 Qt::QueuedConnection);
380 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigMediumChange,
381 this, &UIConsoleEventHandler::sigMediumChange,
382 Qt::QueuedConnection);
383 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigVRDEChange,
384 this, &UIConsoleEventHandler::sigVRDEChange,
385 Qt::QueuedConnection);
386 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigRecordingChange,
387 this, &UIConsoleEventHandler::sigRecordingChange,
388 Qt::QueuedConnection);
389 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigUSBControllerChange,
390 this, &UIConsoleEventHandler::sigUSBControllerChange,
391 Qt::QueuedConnection);
392 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigUSBDeviceStateChange,
393 this, &UIConsoleEventHandler::sigUSBDeviceStateChange,
394 Qt::QueuedConnection);
395 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigSharedFolderChange,
396 this, &UIConsoleEventHandler::sigSharedFolderChange,
397 Qt::QueuedConnection);
398 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigCPUExecutionCapChange,
399 this, &UIConsoleEventHandler::sigCPUExecutionCapChange,
400 Qt::QueuedConnection);
401 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigGuestMonitorChange,
402 this, &UIConsoleEventHandler::sigGuestMonitorChange,
403 Qt::QueuedConnection);
404 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigRuntimeError,
405 this, &UIConsoleEventHandler::sigRuntimeError,
406 Qt::QueuedConnection);
407#ifdef VBOX_WS_MAC
408 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigShowWindow,
409 this, &UIConsoleEventHandler::sigShowWindow,
410 Qt::QueuedConnection);
411#endif /* VBOX_WS_MAC */
412 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigAudioAdapterChange,
413 this, &UIConsoleEventHandler::sigAudioAdapterChange,
414 Qt::QueuedConnection);
415 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigClipboardModeChange,
416 this, &UIConsoleEventHandler::sigClipboardModeChange,
417 Qt::QueuedConnection);
418 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigClipboardError,
419 this, &UIConsoleEventHandler::sigClipboardError,
420 Qt::QueuedConnection);
421 connect(m_pProxy, &UIConsoleEventHandlerProxy::sigDnDModeChange,
422 this, &UIConsoleEventHandler::sigDnDModeChange,
423 Qt::QueuedConnection);
424}
425
426#include "UIConsoleEventHandler.moc"
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use