1 | /* $Id: UIMainEventListener.cpp 103803 2024-03-12 11:15:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMainEventListener 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 | /* Qt includes: */
|
---|
29 | #include <QMutex>
|
---|
30 | #include <QThread>
|
---|
31 |
|
---|
32 | /* GUI includes: */
|
---|
33 | #include "UIGlobalSession.h"
|
---|
34 | #include "UILoggingDefs.h"
|
---|
35 | #include "UIMainEventListener.h"
|
---|
36 | #include "UIMousePointerShapeData.h"
|
---|
37 |
|
---|
38 | /* COM includes: */
|
---|
39 | #include "CCanShowWindowEvent.h"
|
---|
40 | #include "CClipboardErrorEvent.h"
|
---|
41 | #include "CClipboardModeChangedEvent.h"
|
---|
42 | #include "CCloudProfileChangedEvent.h"
|
---|
43 | #include "CCloudProfileRegisteredEvent.h"
|
---|
44 | #include "CCloudProviderListChangedEvent.h"
|
---|
45 | #include "CCloudProviderUninstallEvent.h"
|
---|
46 | #include "CCursorPositionChangedEvent.h"
|
---|
47 | #include "CDnDModeChangedEvent.h"
|
---|
48 | #include "CEvent.h"
|
---|
49 | #include "CEventSource.h"
|
---|
50 | #include "CEventListener.h"
|
---|
51 | #include "CExtraDataCanChangeEvent.h"
|
---|
52 | #include "CExtraDataChangedEvent.h"
|
---|
53 | #include "CExtPackInstalledEvent.h"
|
---|
54 | #include "CExtPackUninstalledEvent.h"
|
---|
55 | #include "CGuestMonitorChangedEvent.h"
|
---|
56 | #include "CGuestProcessIOEvent.h"
|
---|
57 | #include "CGuestProcessRegisteredEvent.h"
|
---|
58 | #include "CGuestProcessStateChangedEvent.h"
|
---|
59 | #include "CGuestSessionRegisteredEvent.h"
|
---|
60 | #include "CGuestSessionStateChangedEvent.h"
|
---|
61 | #include "CKeyboardLedsChangedEvent.h"
|
---|
62 | #include "CMachineDataChangedEvent.h"
|
---|
63 | #include "CMachineStateChangedEvent.h"
|
---|
64 | #include "CMachineRegisteredEvent.h"
|
---|
65 | #include "CMachineGroupsChangedEvent.h"
|
---|
66 | #include "CMediumChangedEvent.h"
|
---|
67 | #include "CMediumConfigChangedEvent.h"
|
---|
68 | #include "CMediumRegisteredEvent.h"
|
---|
69 | #include "CMouseCapabilityChangedEvent.h"
|
---|
70 | #include "CMousePointerShapeChangedEvent.h"
|
---|
71 | #include "CNetworkAdapterChangedEvent.h"
|
---|
72 | #include "CProgressPercentageChangedEvent.h"
|
---|
73 | #include "CProgressTaskCompletedEvent.h"
|
---|
74 | #include "CRuntimeErrorEvent.h"
|
---|
75 | #include "CSessionStateChangedEvent.h"
|
---|
76 | #include "CShowWindowEvent.h"
|
---|
77 | #include "CSnapshotChangedEvent.h"
|
---|
78 | #include "CSnapshotDeletedEvent.h"
|
---|
79 | #include "CSnapshotRestoredEvent.h"
|
---|
80 | #include "CSnapshotTakenEvent.h"
|
---|
81 | #include "CStateChangedEvent.h"
|
---|
82 | #include "CStorageControllerChangedEvent.h"
|
---|
83 | #include "CStorageDeviceChangedEvent.h"
|
---|
84 | #include "CUSBDevice.h"
|
---|
85 | #include "CUSBDeviceStateChangedEvent.h"
|
---|
86 | #include "CVBoxSVCAvailabilityChangedEvent.h"
|
---|
87 | #include "CVirtualBoxErrorInfo.h"
|
---|
88 |
|
---|
89 |
|
---|
90 | /** Private QThread extension allowing to listen for Main events in separate thread.
|
---|
91 | * This thread listens for a Main events infinitely unless creator calls for #setShutdown. */
|
---|
92 | class UIMainEventListeningThread : public QThread
|
---|
93 | {
|
---|
94 | Q_OBJECT;
|
---|
95 |
|
---|
96 | public:
|
---|
97 |
|
---|
98 | /** Constructs Main events listener thread redirecting events from @a comSource to @a comListener.
|
---|
99 | * @param comSource Brings event source we are creating this thread for.
|
---|
100 | * @param comListener Brings event listener we are creating this thread for.
|
---|
101 | * @param escapeEventTypes Brings a set of escape event types which commands this thread to finish. */
|
---|
102 | UIMainEventListeningThread(const CEventSource &comSource,
|
---|
103 | const CEventListener &comListener,
|
---|
104 | const QSet<KVBoxEventType> &escapeEventTypes);
|
---|
105 | /** Destructs Main events listener thread. */
|
---|
106 | virtual ~UIMainEventListeningThread() RT_OVERRIDE;
|
---|
107 |
|
---|
108 | protected:
|
---|
109 |
|
---|
110 | /** Contains the thread excution body. */
|
---|
111 | virtual void run() RT_OVERRIDE;
|
---|
112 |
|
---|
113 | /** Returns whether the thread asked to shutdown prematurely. */
|
---|
114 | bool isShutdown() const;
|
---|
115 | /** Defines whether the thread asked to @a fShutdown prematurely. */
|
---|
116 | void setShutdown(bool fShutdown);
|
---|
117 |
|
---|
118 | private:
|
---|
119 |
|
---|
120 | /** Holds the Main event source reference. */
|
---|
121 | CEventSource m_comSource;
|
---|
122 | /** Holds the Main event listener reference. */
|
---|
123 | CEventListener m_comListener;
|
---|
124 | /** Holds a set of event types this thread should finish job on. */
|
---|
125 | QSet<KVBoxEventType> m_escapeEventTypes;
|
---|
126 |
|
---|
127 | /** Holds the mutex instance which protects thread access. */
|
---|
128 | mutable QMutex m_mutex;
|
---|
129 | /** Holds whether the thread asked to shutdown prematurely. */
|
---|
130 | bool m_fShutdown;
|
---|
131 | };
|
---|
132 |
|
---|
133 |
|
---|
134 | /*********************************************************************************************************************************
|
---|
135 | * Class UIMainEventListeningThread implementation. *
|
---|
136 | *********************************************************************************************************************************/
|
---|
137 |
|
---|
138 | UIMainEventListeningThread::UIMainEventListeningThread(const CEventSource &comSource,
|
---|
139 | const CEventListener &comListener,
|
---|
140 | const QSet<KVBoxEventType> &escapeEventTypes)
|
---|
141 | : m_comSource(comSource)
|
---|
142 | , m_comListener(comListener)
|
---|
143 | , m_escapeEventTypes(escapeEventTypes)
|
---|
144 | , m_fShutdown(false)
|
---|
145 | {
|
---|
146 | setObjectName("UIMainEventListeningThread");
|
---|
147 | }
|
---|
148 |
|
---|
149 | UIMainEventListeningThread::~UIMainEventListeningThread()
|
---|
150 | {
|
---|
151 | /* Make a request to shutdown: */
|
---|
152 | setShutdown(true);
|
---|
153 |
|
---|
154 | /* And wait 30 seconds for run() to finish (1 sec increments to help with
|
---|
155 | delays incurred debugging and prevent suicidal use-after-free behaviour): */
|
---|
156 | uint32_t i = 30000;
|
---|
157 | do
|
---|
158 | wait(1000);
|
---|
159 | while (i-- > 0 && !isFinished());
|
---|
160 | }
|
---|
161 |
|
---|
162 | void UIMainEventListeningThread::run()
|
---|
163 | {
|
---|
164 | /* Initialize COM: */
|
---|
165 | COMBase::InitializeCOM(false);
|
---|
166 |
|
---|
167 | /* Copy source wrapper to this thread: */
|
---|
168 | CEventSource comSource = m_comSource;
|
---|
169 | /* Copy listener wrapper to this thread: */
|
---|
170 | CEventListener comListener = m_comListener;
|
---|
171 |
|
---|
172 | /* While we are not in shutdown: */
|
---|
173 | while (!isShutdown())
|
---|
174 | {
|
---|
175 | /* Fetch the event from the queue: */
|
---|
176 | CEvent comEvent = comSource.GetEvent(comListener, 500);
|
---|
177 | if (!comEvent.isNull())
|
---|
178 | {
|
---|
179 | /* Process the event and tell the listener: */
|
---|
180 | comListener.HandleEvent(comEvent);
|
---|
181 | if (comEvent.GetWaitable())
|
---|
182 | {
|
---|
183 | comSource.EventProcessed(comListener, comEvent);
|
---|
184 | LogRel2(("GUI: UIMainEventListener/ThreadRun: EventProcessed set for waitable event\n"));
|
---|
185 | }
|
---|
186 |
|
---|
187 | /* Check whether we should finish our job on this event: */
|
---|
188 | if (m_escapeEventTypes.contains(comEvent.GetType()))
|
---|
189 | setShutdown(true);
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | /* Cleanup COM: */
|
---|
194 | COMBase::CleanupCOM();
|
---|
195 | }
|
---|
196 |
|
---|
197 | bool UIMainEventListeningThread::isShutdown() const
|
---|
198 | {
|
---|
199 | m_mutex.lock();
|
---|
200 | bool fShutdown = m_fShutdown;
|
---|
201 | m_mutex.unlock();
|
---|
202 | return fShutdown;
|
---|
203 | }
|
---|
204 |
|
---|
205 | void UIMainEventListeningThread::setShutdown(bool fShutdown)
|
---|
206 | {
|
---|
207 | m_mutex.lock();
|
---|
208 | m_fShutdown = fShutdown;
|
---|
209 | m_mutex.unlock();
|
---|
210 | }
|
---|
211 |
|
---|
212 |
|
---|
213 | /*********************************************************************************************************************************
|
---|
214 | * Class UIMainEventListener implementation. *
|
---|
215 | *********************************************************************************************************************************/
|
---|
216 |
|
---|
217 | UIMainEventListener::UIMainEventListener()
|
---|
218 | {
|
---|
219 | /* Register meta-types for required enums. */
|
---|
220 | qRegisterMetaType<KDeviceType>("KDeviceType");
|
---|
221 | qRegisterMetaType<KMachineState>("KMachineState");
|
---|
222 | qRegisterMetaType<KSessionState>("KSessionState");
|
---|
223 | qRegisterMetaType< QVector<uint8_t> >("QVector<uint8_t>");
|
---|
224 | qRegisterMetaType<CNetworkAdapter>("CNetworkAdapter");
|
---|
225 | qRegisterMetaType<CMedium>("CMedium");
|
---|
226 | qRegisterMetaType<CMediumAttachment>("CMediumAttachment");
|
---|
227 | qRegisterMetaType<CUSBDevice>("CUSBDevice");
|
---|
228 | qRegisterMetaType<CVirtualBoxErrorInfo>("CVirtualBoxErrorInfo");
|
---|
229 | qRegisterMetaType<KGuestMonitorChangedEventType>("KGuestMonitorChangedEventType");
|
---|
230 | qRegisterMetaType<CGuestSession>("CGuestSession");
|
---|
231 | }
|
---|
232 |
|
---|
233 | void UIMainEventListener::registerSource(const CEventSource &comSource,
|
---|
234 | const CEventListener &comListener,
|
---|
235 | const QSet<KVBoxEventType> &escapeEventTypes /* = QSet<KVBoxEventType>() */)
|
---|
236 | {
|
---|
237 | /* Make sure source and listener are valid: */
|
---|
238 | AssertReturnVoid(!comSource.isNull());
|
---|
239 | AssertReturnVoid(!comListener.isNull());
|
---|
240 |
|
---|
241 | /* Create thread for passed source: */
|
---|
242 | UIMainEventListeningThread *pThread = new UIMainEventListeningThread(comSource, comListener, escapeEventTypes);
|
---|
243 | if (pThread)
|
---|
244 | {
|
---|
245 | /* Listen for thread finished signal: */
|
---|
246 | connect(pThread, &UIMainEventListeningThread::finished,
|
---|
247 | this, &UIMainEventListener::sltHandleThreadFinished);
|
---|
248 | /* Register & start it: */
|
---|
249 | m_threads << pThread;
|
---|
250 | pThread->start();
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | void UIMainEventListener::unregisterSources()
|
---|
255 | {
|
---|
256 | /* Stop listening for thread finished thread signals,
|
---|
257 | * we are about to destroy these threads anyway: */
|
---|
258 | foreach (UIMainEventListeningThread *pThread, m_threads)
|
---|
259 | disconnect(pThread, &UIMainEventListeningThread::finished,
|
---|
260 | this, &UIMainEventListener::sltHandleThreadFinished);
|
---|
261 |
|
---|
262 | /* Wipe out the threads: */
|
---|
263 | /** @todo r=bird: The use of qDeleteAll here is unsafe because it won't take
|
---|
264 | * QThread::wait() timeouts into account, and may delete the QThread object
|
---|
265 | * while the thread is still running, causing heap corruption/crashes once
|
---|
266 | * the thread awakens and gets on with its termination.
|
---|
267 | * Observed with debugger + paged heap.
|
---|
268 | *
|
---|
269 | * Should use specialized thread list which only deletes the threads after
|
---|
270 | * isFinished() returns true, leaving them alone on timeout failures. */
|
---|
271 | qDeleteAll(m_threads);
|
---|
272 | }
|
---|
273 |
|
---|
274 | STDMETHODIMP UIMainEventListener::HandleEvent(VBoxEventType_T, IEvent *pEvent)
|
---|
275 | {
|
---|
276 | /* Try to acquire COM cleanup protection token first: */
|
---|
277 | if (!gpGlobalSession->comTokenTryLockForRead())
|
---|
278 | return S_OK;
|
---|
279 |
|
---|
280 | CEvent comEvent(pEvent);
|
---|
281 | //printf("Event received: %d\n", comEvent.GetType());
|
---|
282 | switch (comEvent.GetType())
|
---|
283 | {
|
---|
284 | case KVBoxEventType_OnVBoxSVCAvailabilityChanged:
|
---|
285 | {
|
---|
286 | CVBoxSVCAvailabilityChangedEvent comEventSpecific(pEvent);
|
---|
287 | emit sigVBoxSVCAvailabilityChange(comEventSpecific.GetAvailable());
|
---|
288 | break;
|
---|
289 | }
|
---|
290 |
|
---|
291 | case KVBoxEventType_OnMachineStateChanged:
|
---|
292 | {
|
---|
293 | CMachineStateChangedEvent comEventSpecific(pEvent);
|
---|
294 | emit sigMachineStateChange(comEventSpecific.GetMachineId(), comEventSpecific.GetState());
|
---|
295 | break;
|
---|
296 | }
|
---|
297 | case KVBoxEventType_OnMachineDataChanged:
|
---|
298 | {
|
---|
299 | CMachineDataChangedEvent comEventSpecific(pEvent);
|
---|
300 | emit sigMachineDataChange(comEventSpecific.GetMachineId());
|
---|
301 | break;
|
---|
302 | }
|
---|
303 | case KVBoxEventType_OnMachineRegistered:
|
---|
304 | {
|
---|
305 | CMachineRegisteredEvent comEventSpecific(pEvent);
|
---|
306 | emit sigMachineRegistered(comEventSpecific.GetMachineId(), comEventSpecific.GetRegistered());
|
---|
307 | break;
|
---|
308 | }
|
---|
309 | case KVBoxEventType_OnMachineGroupsChanged:
|
---|
310 | {
|
---|
311 | CMachineGroupsChangedEvent comEventSpecific(pEvent);
|
---|
312 | emit sigMachineGroupsChange(comEventSpecific.GetMachineId());
|
---|
313 | break;
|
---|
314 | }
|
---|
315 | case KVBoxEventType_OnSessionStateChanged:
|
---|
316 | {
|
---|
317 | CSessionStateChangedEvent comEventSpecific(pEvent);
|
---|
318 | emit sigSessionStateChange(comEventSpecific.GetMachineId(), comEventSpecific.GetState());
|
---|
319 | break;
|
---|
320 | }
|
---|
321 | case KVBoxEventType_OnSnapshotTaken:
|
---|
322 | {
|
---|
323 | CSnapshotTakenEvent comEventSpecific(pEvent);
|
---|
324 | emit sigSnapshotTake(comEventSpecific.GetMachineId(), comEventSpecific.GetSnapshotId());
|
---|
325 | break;
|
---|
326 | }
|
---|
327 | case KVBoxEventType_OnSnapshotDeleted:
|
---|
328 | {
|
---|
329 | CSnapshotDeletedEvent comEventSpecific(pEvent);
|
---|
330 | emit sigSnapshotDelete(comEventSpecific.GetMachineId(), comEventSpecific.GetSnapshotId());
|
---|
331 | break;
|
---|
332 | }
|
---|
333 | case KVBoxEventType_OnSnapshotChanged:
|
---|
334 | {
|
---|
335 | CSnapshotChangedEvent comEventSpecific(pEvent);
|
---|
336 | emit sigSnapshotChange(comEventSpecific.GetMachineId(), comEventSpecific.GetSnapshotId());
|
---|
337 | break;
|
---|
338 | }
|
---|
339 | case KVBoxEventType_OnSnapshotRestored:
|
---|
340 | {
|
---|
341 | CSnapshotRestoredEvent comEventSpecific(pEvent);
|
---|
342 | emit sigSnapshotRestore(comEventSpecific.GetMachineId(), comEventSpecific.GetSnapshotId());
|
---|
343 | break;
|
---|
344 | }
|
---|
345 | case KVBoxEventType_OnCloudProviderListChanged:
|
---|
346 | {
|
---|
347 | emit sigCloudProviderListChanged();
|
---|
348 | break;
|
---|
349 | }
|
---|
350 | case KVBoxEventType_OnCloudProviderUninstall:
|
---|
351 | {
|
---|
352 | LogRel(("GUI: UIMainEventListener/HandleEvent: KVBoxEventType_OnCloudProviderUninstall event came\n"));
|
---|
353 | CCloudProviderUninstallEvent comEventSpecific(pEvent);
|
---|
354 | emit sigCloudProviderUninstall(comEventSpecific.GetId());
|
---|
355 | LogRel(("GUI: UIMainEventListener/HandleEvent: KVBoxEventType_OnCloudProviderUninstall event done\n"));
|
---|
356 | break;
|
---|
357 | }
|
---|
358 | case KVBoxEventType_OnCloudProfileRegistered:
|
---|
359 | {
|
---|
360 | CCloudProfileRegisteredEvent comEventSpecific(pEvent);
|
---|
361 | emit sigCloudProfileRegistered(comEventSpecific.GetProviderId(), comEventSpecific.GetName(), comEventSpecific.GetRegistered());
|
---|
362 | break;
|
---|
363 | }
|
---|
364 | case KVBoxEventType_OnCloudProfileChanged:
|
---|
365 | {
|
---|
366 | CCloudProfileChangedEvent comEventSpecific(pEvent);
|
---|
367 | emit sigCloudProfileChanged(comEventSpecific.GetProviderId(), comEventSpecific.GetName());
|
---|
368 | break;
|
---|
369 | }
|
---|
370 |
|
---|
371 | case KVBoxEventType_OnExtraDataCanChange:
|
---|
372 | {
|
---|
373 | CExtraDataCanChangeEvent comEventSpecific(pEvent);
|
---|
374 | /* Has to be done in place to give an answer: */
|
---|
375 | bool fVeto = false;
|
---|
376 | QString strReason;
|
---|
377 | emit sigExtraDataCanChange(comEventSpecific.GetMachineId(), comEventSpecific.GetKey(),
|
---|
378 | comEventSpecific.GetValue(), fVeto, strReason);
|
---|
379 | if (fVeto)
|
---|
380 | comEventSpecific.AddVeto(strReason);
|
---|
381 | break;
|
---|
382 | }
|
---|
383 | case KVBoxEventType_OnExtraDataChanged:
|
---|
384 | {
|
---|
385 | CExtraDataChangedEvent comEventSpecific(pEvent);
|
---|
386 | emit sigExtraDataChange(comEventSpecific.GetMachineId(), comEventSpecific.GetKey(), comEventSpecific.GetValue());
|
---|
387 | break;
|
---|
388 | }
|
---|
389 |
|
---|
390 | case KVBoxEventType_OnStorageControllerChanged:
|
---|
391 | {
|
---|
392 | CStorageControllerChangedEvent comEventSpecific(pEvent);
|
---|
393 | emit sigStorageControllerChange(comEventSpecific.GetMachinId(),
|
---|
394 | comEventSpecific.GetControllerName());
|
---|
395 | break;
|
---|
396 | }
|
---|
397 | case KVBoxEventType_OnStorageDeviceChanged:
|
---|
398 | {
|
---|
399 | CStorageDeviceChangedEvent comEventSpecific(pEvent);
|
---|
400 | emit sigStorageDeviceChange(comEventSpecific.GetStorageDevice(),
|
---|
401 | comEventSpecific.GetRemoved(),
|
---|
402 | comEventSpecific.GetSilent());
|
---|
403 | break;
|
---|
404 | }
|
---|
405 | case KVBoxEventType_OnMediumChanged:
|
---|
406 | {
|
---|
407 | CMediumChangedEvent comEventSpecific(pEvent);
|
---|
408 | emit sigMediumChange(comEventSpecific.GetMediumAttachment());
|
---|
409 | break;
|
---|
410 | }
|
---|
411 | case KVBoxEventType_OnMediumConfigChanged:
|
---|
412 | {
|
---|
413 | CMediumConfigChangedEvent comEventSpecific(pEvent);
|
---|
414 | emit sigMediumConfigChange(comEventSpecific.GetMedium());
|
---|
415 | break;
|
---|
416 | }
|
---|
417 | case KVBoxEventType_OnMediumRegistered:
|
---|
418 | {
|
---|
419 | CMediumRegisteredEvent comEventSpecific(pEvent);
|
---|
420 | emit sigMediumRegistered(comEventSpecific.GetMediumId(),
|
---|
421 | comEventSpecific.GetMediumType(),
|
---|
422 | comEventSpecific.GetRegistered());
|
---|
423 | break;
|
---|
424 | }
|
---|
425 |
|
---|
426 | case KVBoxEventType_OnMousePointerShapeChanged:
|
---|
427 | {
|
---|
428 | CMousePointerShapeChangedEvent comEventSpecific(pEvent);
|
---|
429 | UIMousePointerShapeData shapeData(comEventSpecific.GetVisible(),
|
---|
430 | comEventSpecific.GetAlpha(),
|
---|
431 | QPoint(comEventSpecific.GetXhot(), comEventSpecific.GetYhot()),
|
---|
432 | QSize(comEventSpecific.GetWidth(), comEventSpecific.GetHeight()),
|
---|
433 | comEventSpecific.GetShape());
|
---|
434 | emit sigMousePointerShapeChange(shapeData);
|
---|
435 | break;
|
---|
436 | }
|
---|
437 | case KVBoxEventType_OnMouseCapabilityChanged:
|
---|
438 | {
|
---|
439 | CMouseCapabilityChangedEvent comEventSpecific(pEvent);
|
---|
440 | emit sigMouseCapabilityChange(comEventSpecific.GetSupportsAbsolute(), comEventSpecific.GetSupportsRelative(),
|
---|
441 | comEventSpecific.GetSupportsTouchScreen(), comEventSpecific.GetSupportsTouchPad(),
|
---|
442 | comEventSpecific.GetNeedsHostCursor());
|
---|
443 | break;
|
---|
444 | }
|
---|
445 | case KVBoxEventType_OnCursorPositionChanged:
|
---|
446 | {
|
---|
447 | CCursorPositionChangedEvent comEventSpecific(pEvent);
|
---|
448 | emit sigCursorPositionChange(comEventSpecific.GetHasData(),
|
---|
449 | (unsigned long)comEventSpecific.GetX(), (unsigned long)comEventSpecific.GetY());
|
---|
450 | break;
|
---|
451 | }
|
---|
452 | case KVBoxEventType_OnKeyboardLedsChanged:
|
---|
453 | {
|
---|
454 | CKeyboardLedsChangedEvent comEventSpecific(pEvent);
|
---|
455 | emit sigKeyboardLedsChange(comEventSpecific.GetNumLock(),
|
---|
456 | comEventSpecific.GetCapsLock(),
|
---|
457 | comEventSpecific.GetScrollLock());
|
---|
458 | break;
|
---|
459 | }
|
---|
460 | case KVBoxEventType_OnStateChanged:
|
---|
461 | {
|
---|
462 | CStateChangedEvent comEventSpecific(pEvent);
|
---|
463 | emit sigStateChange(comEventSpecific.GetState());
|
---|
464 | break;
|
---|
465 | }
|
---|
466 | case KVBoxEventType_OnAdditionsStateChanged:
|
---|
467 | {
|
---|
468 | emit sigAdditionsChange();
|
---|
469 | break;
|
---|
470 | }
|
---|
471 | case KVBoxEventType_OnNetworkAdapterChanged:
|
---|
472 | {
|
---|
473 | CNetworkAdapterChangedEvent comEventSpecific(pEvent);
|
---|
474 | emit sigNetworkAdapterChange(comEventSpecific.GetNetworkAdapter());
|
---|
475 | break;
|
---|
476 | }
|
---|
477 | case KVBoxEventType_OnVRDEServerChanged:
|
---|
478 | case KVBoxEventType_OnVRDEServerInfoChanged:
|
---|
479 | {
|
---|
480 | emit sigVRDEChange();
|
---|
481 | break;
|
---|
482 | }
|
---|
483 | case KVBoxEventType_OnRecordingChanged:
|
---|
484 | {
|
---|
485 | emit sigRecordingChange();
|
---|
486 | break;
|
---|
487 | }
|
---|
488 | case KVBoxEventType_OnUSBControllerChanged:
|
---|
489 | {
|
---|
490 | emit sigUSBControllerChange();
|
---|
491 | break;
|
---|
492 | }
|
---|
493 | case KVBoxEventType_OnUSBDeviceStateChanged:
|
---|
494 | {
|
---|
495 | CUSBDeviceStateChangedEvent comEventSpecific(pEvent);
|
---|
496 | emit sigUSBDeviceStateChange(comEventSpecific.GetDevice(),
|
---|
497 | comEventSpecific.GetAttached(),
|
---|
498 | comEventSpecific.GetError());
|
---|
499 | break;
|
---|
500 | }
|
---|
501 | case KVBoxEventType_OnSharedFolderChanged:
|
---|
502 | {
|
---|
503 | emit sigSharedFolderChange();
|
---|
504 | break;
|
---|
505 | }
|
---|
506 | case KVBoxEventType_OnCPUExecutionCapChanged:
|
---|
507 | {
|
---|
508 | emit sigCPUExecutionCapChange();
|
---|
509 | break;
|
---|
510 | }
|
---|
511 | case KVBoxEventType_OnGuestMonitorChanged:
|
---|
512 | {
|
---|
513 | CGuestMonitorChangedEvent comEventSpecific(pEvent);
|
---|
514 | emit sigGuestMonitorChange(comEventSpecific.GetChangeType(), comEventSpecific.GetScreenId(),
|
---|
515 | QRect(comEventSpecific.GetOriginX(), comEventSpecific.GetOriginY(),
|
---|
516 | comEventSpecific.GetWidth(), comEventSpecific.GetHeight()));
|
---|
517 | break;
|
---|
518 | }
|
---|
519 | case KVBoxEventType_OnRuntimeError:
|
---|
520 | {
|
---|
521 | CRuntimeErrorEvent comEventSpecific(pEvent);
|
---|
522 | emit sigRuntimeError(comEventSpecific.GetFatal(), comEventSpecific.GetId(), comEventSpecific.GetMessage());
|
---|
523 | break;
|
---|
524 | }
|
---|
525 | case KVBoxEventType_OnCanShowWindow:
|
---|
526 | {
|
---|
527 | CCanShowWindowEvent comEventSpecific(pEvent);
|
---|
528 | /* Has to be done in place to give an answer: */
|
---|
529 | bool fVeto = false;
|
---|
530 | QString strReason;
|
---|
531 | emit sigCanShowWindow(fVeto, strReason);
|
---|
532 | if (fVeto)
|
---|
533 | comEventSpecific.AddVeto(strReason);
|
---|
534 | else
|
---|
535 | comEventSpecific.AddApproval(strReason);
|
---|
536 | break;
|
---|
537 | }
|
---|
538 | case KVBoxEventType_OnShowWindow:
|
---|
539 | {
|
---|
540 | CShowWindowEvent comEventSpecific(pEvent);
|
---|
541 | /* Has to be done in place to give an answer: */
|
---|
542 | qint64 winId = comEventSpecific.GetWinId();
|
---|
543 | if (winId != 0)
|
---|
544 | break; /* Already set by some listener. */
|
---|
545 | emit sigShowWindow(winId);
|
---|
546 | comEventSpecific.SetWinId(winId);
|
---|
547 | break;
|
---|
548 | }
|
---|
549 | case KVBoxEventType_OnAudioAdapterChanged:
|
---|
550 | {
|
---|
551 | emit sigAudioAdapterChange();
|
---|
552 | break;
|
---|
553 | }
|
---|
554 |
|
---|
555 | case KVBoxEventType_OnProgressPercentageChanged:
|
---|
556 | {
|
---|
557 | CProgressPercentageChangedEvent comEventSpecific(pEvent);
|
---|
558 | emit sigProgressPercentageChange(comEventSpecific.GetProgressId(), (int)comEventSpecific.GetPercent());
|
---|
559 | break;
|
---|
560 | }
|
---|
561 | case KVBoxEventType_OnProgressTaskCompleted:
|
---|
562 | {
|
---|
563 | CProgressTaskCompletedEvent comEventSpecific(pEvent);
|
---|
564 | emit sigProgressTaskComplete(comEventSpecific.GetProgressId());
|
---|
565 | break;
|
---|
566 | }
|
---|
567 |
|
---|
568 | case KVBoxEventType_OnGuestSessionRegistered:
|
---|
569 | {
|
---|
570 | CGuestSessionRegisteredEvent comEventSpecific(pEvent);
|
---|
571 | if (comEventSpecific.GetRegistered())
|
---|
572 | emit sigGuestSessionRegistered(comEventSpecific.GetSession());
|
---|
573 | else
|
---|
574 | emit sigGuestSessionUnregistered(comEventSpecific.GetSession());
|
---|
575 | break;
|
---|
576 | }
|
---|
577 | case KVBoxEventType_OnGuestProcessRegistered:
|
---|
578 | {
|
---|
579 | CGuestProcessRegisteredEvent comEventSpecific(pEvent);
|
---|
580 | if (comEventSpecific.GetRegistered())
|
---|
581 | emit sigGuestProcessRegistered(comEventSpecific.GetProcess());
|
---|
582 | else
|
---|
583 | emit sigGuestProcessUnregistered(comEventSpecific.GetProcess());
|
---|
584 | break;
|
---|
585 | }
|
---|
586 | case KVBoxEventType_OnGuestSessionStateChanged:
|
---|
587 | {
|
---|
588 | CGuestSessionStateChangedEvent comEventSpecific(pEvent);
|
---|
589 | emit sigGuestSessionStatedChanged(comEventSpecific);
|
---|
590 | break;
|
---|
591 | }
|
---|
592 | case KVBoxEventType_OnGuestProcessInputNotify:
|
---|
593 | case KVBoxEventType_OnGuestProcessOutput:
|
---|
594 | {
|
---|
595 | break;
|
---|
596 | }
|
---|
597 | case KVBoxEventType_OnGuestProcessStateChanged:
|
---|
598 | {
|
---|
599 | CGuestProcessStateChangedEvent comEventSpecific(pEvent);
|
---|
600 | comEventSpecific.GetError();
|
---|
601 | emit sigGuestProcessStateChanged(comEventSpecific);
|
---|
602 | break;
|
---|
603 | }
|
---|
604 | case KVBoxEventType_OnGuestFileRegistered:
|
---|
605 | case KVBoxEventType_OnGuestFileStateChanged:
|
---|
606 | case KVBoxEventType_OnGuestFileOffsetChanged:
|
---|
607 | case KVBoxEventType_OnGuestFileRead:
|
---|
608 | case KVBoxEventType_OnGuestFileWrite:
|
---|
609 | {
|
---|
610 | break;
|
---|
611 | }
|
---|
612 | case KVBoxEventType_OnClipboardModeChanged:
|
---|
613 | {
|
---|
614 | CClipboardModeChangedEvent comEventSpecific(pEvent);
|
---|
615 | emit sigClipboardModeChange(comEventSpecific.GetClipboardMode());
|
---|
616 | break;
|
---|
617 | }
|
---|
618 | case KVBoxEventType_OnClipboardError:
|
---|
619 | {
|
---|
620 | CClipboardErrorEvent comEventSpecific(pEvent);
|
---|
621 | emit sigClipboardError(comEventSpecific.GetId(), comEventSpecific.GetMsg(), comEventSpecific.GetRcError());
|
---|
622 | break;
|
---|
623 | }
|
---|
624 | case KVBoxEventType_OnDnDModeChanged:
|
---|
625 | {
|
---|
626 | CDnDModeChangedEvent comEventSpecific(pEvent);
|
---|
627 | emit sigDnDModeChange(comEventSpecific.GetDndMode());
|
---|
628 | break;
|
---|
629 | }
|
---|
630 | case KVBoxEventType_OnExtPackInstalled:
|
---|
631 | {
|
---|
632 | CExtPackInstalledEvent comEventSpecific(pEvent);
|
---|
633 | emit sigExtensionPackInstalled(comEventSpecific.GetName());
|
---|
634 | break;
|
---|
635 | }
|
---|
636 | case KVBoxEventType_OnExtPackUninstalled:
|
---|
637 | {
|
---|
638 | CExtPackInstalledEvent comEventSpecific(pEvent);
|
---|
639 | emit sigExtensionPackUninstalled(comEventSpecific.GetName());
|
---|
640 | break;
|
---|
641 | }
|
---|
642 | default: break;
|
---|
643 | }
|
---|
644 |
|
---|
645 | /* Unlock COM cleanup protection token: */
|
---|
646 | gpGlobalSession->comTokenUnlock();
|
---|
647 |
|
---|
648 | return S_OK;
|
---|
649 | }
|
---|
650 |
|
---|
651 | void UIMainEventListener::sltHandleThreadFinished()
|
---|
652 | {
|
---|
653 | /* We have received a signal about thread finished, that means we were
|
---|
654 | * patiently waiting for it, instead of killing UIMainEventListener object. */
|
---|
655 | UIMainEventListeningThread *pSender = qobject_cast<UIMainEventListeningThread*>(sender());
|
---|
656 | AssertPtrReturnVoid(pSender);
|
---|
657 |
|
---|
658 | /* We should remove corresponding thread from the list: */
|
---|
659 | const int iIndex = m_threads.indexOf(pSender);
|
---|
660 | delete m_threads.value(iIndex);
|
---|
661 | m_threads.removeAt(iIndex);
|
---|
662 |
|
---|
663 | /* And notify listeners we have really finished: */
|
---|
664 | if (m_threads.isEmpty())
|
---|
665 | emit sigListeningFinished();
|
---|
666 | }
|
---|
667 |
|
---|
668 | #include "UIMainEventListener.moc"
|
---|