VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp@ 98490

Last change on this file since 98490 was 98490, checked in by vboxsync, 2 years ago

FE/Qt: bugref:10322: Runtime UI: Reworking UIIndicatorsPool virtualization features indicator to move COM related logic to UISession.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 32.4 KB
Line 
1/* $Id: UISession.cpp 98490 2023-02-07 12:11:07Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UISession class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-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 <QApplication>
30#include <QWidget>
31#ifdef VBOX_WS_WIN
32# include <iprt/win/windows.h> /* Workaround for compile errors if included directly by QtWin. */
33# include <QtWin>
34#endif
35
36/* GUI includes: */
37#include "UIActionPoolRuntime.h"
38#include "UICommon.h"
39#include "UIConsoleEventHandler.h"
40#include "UIDetailsGenerator.h"
41#include "UIExtraDataManager.h"
42#include "UIFrameBuffer.h"
43#include "UIMachine.h"
44#include "UIMachineLogic.h"
45#include "UIMachineView.h"
46#include "UIMachineWindow.h"
47#include "UIMedium.h"
48#include "UIMessageCenter.h"
49#include "UIMousePointerShapeData.h"
50#include "UINotificationCenter.h"
51#include "UISession.h"
52#include "UISettingsDialogSpecific.h"
53#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
54# include "UIKeyboardHandler.h"
55# include <signal.h>
56#endif
57
58/* COM includes: */
59#include "CGraphicsAdapter.h"
60#include "CHostNetworkInterface.h"
61#include "CHostUSBDevice.h"
62#include "CMedium.h"
63#include "CMediumAttachment.h"
64#include "CSnapshot.h"
65#include "CStorageController.h"
66#include "CSystemProperties.h"
67#include "CUSBController.h"
68#include "CUSBDeviceFilter.h"
69#include "CUSBDeviceFilters.h"
70#ifdef VBOX_WITH_NETFLT
71# include "CNetworkAdapter.h"
72#endif
73
74/* External includes: */
75#ifdef VBOX_WS_X11
76# include <X11/Xlib.h>
77# include <X11/Xutil.h>
78#endif
79
80
81#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
82static void signalHandlerSIGUSR1(int sig, siginfo_t *, void *);
83#endif
84
85/* static */
86bool UISession::create(UISession *&pSession, UIMachine *pMachine)
87{
88 /* Make sure NULL pointer passed: */
89 AssertReturn(!pSession, false);
90
91 /* Create session UI: */
92 pSession = new UISession(pMachine);
93 AssertPtrReturn(pSession, false);
94
95 /* Make sure it's prepared: */
96 if (!pSession->prepare())
97 {
98 /* Destroy session UI otherwise: */
99 destroy(pSession);
100 /* False in that case: */
101 return false;
102 }
103
104 /* True by default: */
105 return true;
106}
107
108/* static */
109void UISession::destroy(UISession *&pSession)
110{
111 /* Make sure valid pointer passed: */
112 AssertPtrReturnVoid(pSession);
113
114 /* Delete session: */
115 delete pSession;
116 pSession = 0;
117}
118
119bool UISession::initialize()
120{
121 /* Preprocess initialization: */
122 if (!preprocessInitialization())
123 return false;
124
125 /* Notify user about mouse&keyboard auto-capturing: */
126 if (gEDataManager->autoCaptureEnabled())
127 UINotificationMessage::remindAboutAutoCapture();
128
129 m_enmMachineState = machine().GetState();
130
131 /* Apply debug settings from the command line. */
132 if (!debugger().isNull() && debugger().isOk())
133 {
134 if (uiCommon().areWeToExecuteAllInIem())
135 debugger().SetExecuteAllInIEM(true);
136 if (!uiCommon().isDefaultWarpPct())
137 debugger().SetVirtualTimeRate(uiCommon().getWarpPct());
138 }
139
140 /* Apply ad-hoc reconfigurations from the command line: */
141 if (uiCommon().hasFloppyImageToMount())
142 mountAdHocImage(KDeviceType_Floppy, UIMediumDeviceType_Floppy, uiCommon().getFloppyImage().toString());
143 if (uiCommon().hasDvdImageToMount())
144 mountAdHocImage(KDeviceType_DVD, UIMediumDeviceType_DVD, uiCommon().getDvdImage().toString());
145
146 /* Power UP if this is NOT separate process: */
147 if (!uiCommon().isSeparateProcess())
148 if (!powerUp())
149 return false;
150
151 /* Make sure all the pending Console events converted to signals
152 * during the powerUp() progress above reached their destinations.
153 * That is necessary to make sure all the pending machine state change events processed.
154 * We can't just use the machine state directly acquired from IMachine because there
155 * will be few places which are using stale machine state, not just this one. */
156 QApplication::sendPostedEvents(0, QEvent::MetaCall);
157
158 /* Check if we missed a really quick termination after successful startup: */
159 if (isTurnedOff())
160 {
161 LogRel(("GUI: Aborting startup due to invalid machine state detected: %d\n", machineState()));
162 return false;
163 }
164
165 /* Fetch corresponding states: */
166 if (uiCommon().isSeparateProcess())
167 {
168 sltAdditionsChange();
169 }
170 machineLogic()->initializePostPowerUp();
171
172#ifdef VBOX_GUI_WITH_PIDFILE
173 uiCommon().createPidfile();
174#endif /* VBOX_GUI_WITH_PIDFILE */
175
176 /* True by default: */
177 return true;
178}
179
180bool UISession::powerUp()
181{
182 /* Power UP machine: */
183 CProgress comProgress = uiCommon().shouldStartPaused() ? console().PowerUpPaused() : console().PowerUp();
184
185 /* Check for immediate failure: */
186 if (!console().isOk() || comProgress.isNull())
187 {
188 if (uiCommon().showStartVMErrors())
189 msgCenter().cannotStartMachine(console(), machineName());
190 LogRel(("GUI: Aborting startup due to power up issue detected...\n"));
191 return false;
192 }
193
194 /* Some logging right after we powered up: */
195 LogRel(("GUI: Qt version: %s\n", UICommon::qtRTVersionString().toUtf8().constData()));
196#ifdef VBOX_WS_X11
197 LogRel(("GUI: X11 Window Manager code: %d\n", (int)uiCommon().typeOfWindowManager()));
198#endif
199#if defined(VBOX_WS_MAC) || defined(VBOX_WS_WIN)
200 LogRel(("GUI: HID LEDs sync is %s\n", uimachine()->isHidLedsSyncEnabled() ? "enabled" : "disabled"));
201#else
202 LogRel(("GUI: HID LEDs sync is not supported on this platform\n"));
203#endif
204
205 /* Enable 'manual-override',
206 * preventing automatic Runtime UI closing
207 * and visual representation mode changes: */
208 uimachine()->setManualOverrideMode(true);
209
210 /* Show "Starting/Restoring" progress dialog: */
211 if (isSaved())
212 {
213 msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_state_restore_90px.png", 0, 0);
214 /* After restoring from 'saved' state, machine-window(s) geometry should be adjusted: */
215 machineLogic()->adjustMachineWindowsGeometry();
216 }
217 else
218 {
219#ifdef VBOX_IS_QT6_OR_LATER /** @todo why is this any problem on qt6? */
220 msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_start_90px.png", 0, 0);
221#else
222 msgCenter().showModalProgressDialog(comProgress, machineName(), ":/progress_start_90px.png");
223#endif
224 /* After VM start, machine-window(s) size-hint(s) should be sent: */
225 machineLogic()->sendMachineWindowsSizeHints();
226 }
227
228 /* Check for progress failure: */
229 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)
230 {
231 if (uiCommon().showStartVMErrors())
232 msgCenter().cannotStartMachine(comProgress, machineName());
233 LogRel(("GUI: Aborting startup due to power up progress issue detected...\n"));
234 return false;
235 }
236
237 /* Disable 'manual-override' finally: */
238 uimachine()->setManualOverrideMode(false);
239
240 /* True by default: */
241 return true;
242}
243
244WId UISession::mainMachineWindowId() const
245{
246 return mainMachineWindow() ? mainMachineWindow()->winId() : 0;
247}
248
249bool UISession::setPause(bool fPause)
250{
251 if (fPause)
252 console().Pause();
253 else
254 console().Resume();
255
256 const bool fOk = console().isOk();
257 if (!fOk)
258 {
259 if (fPause)
260 UINotificationMessage::cannotPauseMachine(console());
261 else
262 UINotificationMessage::cannotResumeMachine(console());
263 }
264
265 return fOk;
266}
267
268bool UISession::guestAdditionsUpgradable()
269{
270 if (!machine().isOk())
271 return false;
272
273 /* Auto GA update is currently for Windows and Linux guests only */
274 const CGuestOSType osType = uiCommon().vmGuestOSType(machine().GetOSTypeId());
275 if (!osType.isOk())
276 return false;
277
278 const QString strGuestFamily = osType.GetFamilyId();
279 bool fIsWindowOrLinux = strGuestFamily.contains("windows", Qt::CaseInsensitive) || strGuestFamily.contains("linux", Qt::CaseInsensitive);
280
281 if (!fIsWindowOrLinux)
282 return false;
283
284 /* Also check whether we have something to update automatically: */
285 if (m_ulGuestAdditionsRunLevel < (ULONG)KAdditionsRunLevelType_Userland)
286 return false;
287
288 return true;
289}
290
291UIFrameBuffer *UISession::frameBuffer(ulong uScreenId) const
292{
293 Assert(uScreenId < (ulong)m_frameBufferVector.size());
294 return m_frameBufferVector.value((int)uScreenId, 0);
295}
296
297void UISession::setFrameBuffer(ulong uScreenId, UIFrameBuffer *pFrameBuffer)
298{
299 Assert(uScreenId < (ulong)m_frameBufferVector.size());
300 if (uScreenId < (ulong)m_frameBufferVector.size())
301 m_frameBufferVector[(int)uScreenId] = pFrameBuffer;
302}
303
304QSize UISession::frameBufferSize(ulong uScreenId) const
305{
306 UIFrameBuffer *pFramebuffer = frameBuffer(uScreenId);
307 return pFramebuffer ? QSize(pFramebuffer->width(), pFramebuffer->height()) : QSize();
308}
309
310void UISession::acquireDeviceActivity(const QVector<KDeviceType> &deviceTypes, QVector<KDeviceActivity> &states)
311{
312 CConsole comConsole = console();
313 states = comConsole.GetDeviceActivity(deviceTypes);
314 if (!comConsole.isOk())
315 UINotificationMessage::cannotAcquireConsoleParameter(comConsole);
316}
317
318void UISession::acquireHardDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent)
319{
320 CMachine comMachine = machine();
321 UIDetailsGenerator::acquireHardDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent);
322}
323
324void UISession::acquireOpticalDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent, bool &fAttachmentsMounted)
325{
326 CMachine comMachine = machine();
327 UIDetailsGenerator::acquireOpticalDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent, fAttachmentsMounted);
328}
329
330void UISession::acquireFloppyDiskStatusInfo(QString &strInfo, bool &fAttachmentsPresent, bool &fAttachmentsMounted)
331{
332 CMachine comMachine = machine();
333 UIDetailsGenerator::acquireFloppyDiskStatusInfo(comMachine, strInfo, fAttachmentsPresent, fAttachmentsMounted);
334}
335
336void UISession::acquireAudioStatusInfo(QString &strInfo, bool &fAudioEnabled, bool &fEnabledOutput, bool &fEnabledInput)
337{
338 CMachine comMachine = machine();
339 UIDetailsGenerator::acquireAudioStatusInfo(comMachine, strInfo, fAudioEnabled, fEnabledOutput, fEnabledInput);
340}
341
342void UISession::acquireNetworkStatusInfo(QString &strInfo, bool &fAdaptersPresent, bool &fCablesDisconnected)
343{
344 CMachine comMachine = machine();
345 UIDetailsGenerator::acquireNetworkStatusInfo(comMachine, strInfo, fAdaptersPresent, fCablesDisconnected);
346}
347
348void UISession::acquireUsbStatusInfo(QString &strInfo, bool &fUsbEnableds)
349{
350 CMachine comMachine = machine();
351 CConsole comConsole = console();
352 UIDetailsGenerator::acquireUsbStatusInfo(comMachine, comConsole, strInfo, fUsbEnableds);
353}
354
355void UISession::acquireSharedFoldersStatusInfo(QString &strInfo, bool &fFoldersPresent)
356{
357 CMachine comMachine = machine();
358 CConsole comConsole = console();
359 CGuest comGuest = guest();
360 UIDetailsGenerator::acquireSharedFoldersStatusInfo(comMachine, comConsole, comGuest, strInfo, fFoldersPresent);
361}
362
363void UISession::acquireDisplayStatusInfo(QString &strInfo, bool &fAcceleration3D)
364{
365 CMachine comMachine = machine();
366 UIDetailsGenerator::acquireDisplayStatusInfo(comMachine, strInfo, fAcceleration3D);
367}
368
369void UISession::acquireRecordingStatusInfo(QString &strInfo, bool &fRecordingEnabled, bool &fMachinePaused)
370{
371 CMachine comMachine = machine();
372 fMachinePaused = isPaused();
373 UIDetailsGenerator::acquireRecordingStatusInfo(comMachine, strInfo, fRecordingEnabled);
374}
375
376void UISession::acquireCpuLoadPercentage(int &iPercentage)
377{
378 CMachineDebugger comDebugger = debugger();
379 ULONG uPctExecuting;
380 ULONG uPctHalted;
381 ULONG uPctOther;
382 comDebugger.GetCPULoad(0x7fffffff, uPctExecuting, uPctHalted, uPctOther);
383 iPercentage = uPctExecuting + uPctOther;
384}
385
386void UISession::acquireFeaturesStatusInfo(QString &strInfo, KVMExecutionEngine &enmEngine,
387 bool fNestedPagingEnabled, bool fUxEnabled,
388 KParavirtProvider enmProvider)
389{
390 CMachine comMachine = machine();
391 UIDetailsGenerator::acquireFeaturesStatusInfo(comMachine, strInfo,
392 enmEngine,
393 fNestedPagingEnabled, fUxEnabled,
394 enmProvider);
395}
396
397bool UISession::prepareToBeSaved()
398{
399 return isPaused()
400 || (isRunning() && pause());
401}
402
403bool UISession::prepareToBeShutdowned()
404{
405 const bool fValidMode = console().GetGuestEnteredACPIMode();
406 if (!fValidMode)
407 UINotificationMessage::cannotSendACPIToMachine();
408 return fValidMode;
409}
410
411void UISession::sltInstallGuestAdditionsFrom(const QString &strSource)
412{
413 if (!guestAdditionsUpgradable())
414 return sltMountDVDAdHoc(strSource);
415
416 /* Update guest additions automatically: */
417 UINotificationProgressGuestAdditionsInstall *pNotification =
418 new UINotificationProgressGuestAdditionsInstall(guest(), strSource);
419 connect(pNotification, &UINotificationProgressGuestAdditionsInstall::sigGuestAdditionsInstallationFailed,
420 this, &UISession::sltMountDVDAdHoc);
421 gpNotificationCenter->append(pNotification);
422}
423
424void UISession::sltMountDVDAdHoc(const QString &strSource)
425{
426 mountAdHocImage(KDeviceType_DVD, UIMediumDeviceType_DVD, strSource);
427}
428
429void UISession::sltDetachCOM()
430{
431 /* Cleanup everything COM related: */
432 cleanupFramebuffers();
433 cleanupConsoleEventHandlers();
434 cleanupNotificationCenter();
435 cleanupSession();
436}
437
438void UISession::sltStateChange(KMachineState enmState)
439{
440 /* Check if something had changed: */
441 if (m_enmMachineState != enmState)
442 {
443 /* Store new data: */
444 m_enmMachineStatePrevious = m_enmMachineState;
445 m_enmMachineState = enmState;
446
447 /* Notify listeners about machine state changed: */
448 emit sigMachineStateChange();
449 }
450}
451
452void UISession::sltAdditionsChange()
453{
454 /* Acquire actual states: */
455 const ULONG ulGuestAdditionsRunLevel = guest().GetAdditionsRunLevel();
456 LONG64 lLastUpdatedIgnored;
457 const bool fIsGuestSupportsGraphics = guest().GetFacilityStatus(KAdditionsFacilityType_Graphics, lLastUpdatedIgnored)
458 == KAdditionsFacilityStatus_Active;
459 const bool fIsGuestSupportsSeamless = guest().GetFacilityStatus(KAdditionsFacilityType_Seamless, lLastUpdatedIgnored)
460 == KAdditionsFacilityStatus_Active;
461
462 /* Check if something had changed: */
463 if ( m_ulGuestAdditionsRunLevel != ulGuestAdditionsRunLevel
464 || m_fIsGuestSupportsGraphics != fIsGuestSupportsGraphics
465 || m_fIsGuestSupportsSeamless != fIsGuestSupportsSeamless)
466 {
467 /* Store new data: */
468 m_ulGuestAdditionsRunLevel = ulGuestAdditionsRunLevel;
469 m_fIsGuestSupportsGraphics = fIsGuestSupportsGraphics;
470 m_fIsGuestSupportsSeamless = fIsGuestSupportsSeamless;
471
472 /* Notify listeners about GA state really changed: */
473 LogRel(("GUI: UISession::sltAdditionsChange: GA state really changed, notifying listeners.\n"));
474 emit sigAdditionsStateActualChange();
475 }
476 else
477 LogRel(("GUI: UISession::sltAdditionsChange: GA state doesn't really changed, still notifying listeners.\n"));
478
479 /* Notify listeners about GA state change event came: */
480 emit sigAdditionsStateChange();
481}
482
483UISession::UISession(UIMachine *pMachine)
484 : QObject(pMachine)
485 /* Base variables: */
486 , m_pMachine(pMachine)
487 , m_pConsoleEventhandler(0)
488 /* Common variables: */
489 , m_enmMachineStatePrevious(KMachineState_Null)
490 , m_enmMachineState(KMachineState_Null)
491 /* Guest additions flags: */
492 , m_ulGuestAdditionsRunLevel(0)
493 , m_fIsGuestSupportsGraphics(false)
494 , m_fIsGuestSupportsSeamless(false)
495{
496}
497
498UISession::~UISession()
499{
500}
501
502bool UISession::prepare()
503{
504 /* Prepare COM stuff: */
505 if (!prepareSession())
506 return false;
507
508 /* Cache media early if requested: */
509 if (uiCommon().agressiveCaching())
510 recacheMachineMedia();
511
512 /* Prepare GUI stuff: */
513 prepareNotificationCenter();
514 prepareConsoleEventHandlers();
515 prepareFramebuffers();
516 prepareConnections();
517 prepareSignalHandling();
518
519 /* True by default: */
520 return true;
521}
522
523bool UISession::prepareSession()
524{
525 /* Open session: */
526 m_comSession = uiCommon().openSession(uiCommon().managedVMUuid(),
527 uiCommon().isSeparateProcess()
528 ? KLockType_Shared
529 : KLockType_VM);
530 if (m_comSession.isNull())
531 return false;
532
533 /* Get machine: */
534 m_comMachine = m_comSession.GetMachine();
535 if (m_comMachine.isNull())
536 return false;
537
538 /* Get console: */
539 m_comConsole = m_comSession.GetConsole();
540 if (m_comConsole.isNull())
541 return false;
542
543 /* Get display: */
544 m_comDisplay = m_comConsole.GetDisplay();
545 if (m_comDisplay.isNull())
546 return false;
547
548 /* Get guest: */
549 m_comGuest = m_comConsole.GetGuest();
550 if (m_comGuest.isNull())
551 return false;
552
553 /* Get mouse: */
554 m_comMouse = m_comConsole.GetMouse();
555 if (m_comMouse.isNull())
556 return false;
557
558 /* Get keyboard: */
559 m_comKeyboard = m_comConsole.GetKeyboard();
560 if (m_comKeyboard.isNull())
561 return false;
562
563 /* Get debugger: */
564 m_comDebugger = m_comConsole.GetDebugger();
565 if (m_comDebugger.isNull())
566 return false;
567
568 /* Update machine-name: */
569 m_strMachineName = machine().GetName();
570
571 /* Update machine-state: */
572 m_enmMachineState = machine().GetState();
573
574 /* True by default: */
575 return true;
576}
577
578void UISession::prepareNotificationCenter()
579{
580 UINotificationCenter::create();
581}
582
583void UISession::prepareConsoleEventHandlers()
584{
585 /* Create console event-handler: */
586 m_pConsoleEventhandler = new UIConsoleEventHandler(this);
587
588 /* Console event connections: */
589 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigAdditionsChange,
590 this, &UISession::sltAdditionsChange);
591 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigAudioAdapterChange,
592 this, &UISession::sigAudioAdapterChange);
593 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigClipboardModeChange,
594 this, &UISession::sigClipboardModeChange);
595 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigCPUExecutionCapChange,
596 this, &UISession::sigCPUExecutionCapChange);
597 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigDnDModeChange,
598 this, &UISession::sigDnDModeChange);
599 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigGuestMonitorChange,
600 this, &UISession::sigGuestMonitorChange);
601 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMediumChange,
602 this, &UISession::sigMediumChange);
603 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigNetworkAdapterChange,
604 this, &UISession::sigNetworkAdapterChange);
605 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigRecordingChange,
606 this, &UISession::sigRecordingChange);
607 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigSharedFolderChange,
608 this, &UISession::sigSharedFolderChange);
609 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigStateChange,
610 this, &UISession::sltStateChange);
611 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigStorageDeviceChange,
612 this, &UISession::sigStorageDeviceChange);
613 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigUSBControllerChange,
614 this, &UISession::sigUSBControllerChange);
615 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigUSBDeviceStateChange,
616 this, &UISession::sigUSBDeviceStateChange);
617 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigVRDEChange,
618 this, &UISession::sigVRDEChange);
619 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigRuntimeError,
620 this, &UISession::sigRuntimeError);
621
622#ifdef VBOX_WS_MAC
623 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigShowWindow,
624 this, &UISession::sigShowWindows, Qt::QueuedConnection);
625#endif
626
627 /* Console keyboard connections: */
628 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigKeyboardLedsChange,
629 this, &UISession::sigKeyboardLedsChange);
630
631 /* Console mouse connections: */
632 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMousePointerShapeChange,
633 this, &UISession::sigMousePointerShapeChange);
634 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigMouseCapabilityChange,
635 this, &UISession::sigMouseCapabilityChange);
636 connect(m_pConsoleEventhandler, &UIConsoleEventHandler::sigCursorPositionChange,
637 this, &UISession::sigCursorPositionChange);
638}
639
640void UISession::prepareFramebuffers()
641{
642 /* Each framebuffer will be really prepared on first UIMachineView creation: */
643 m_frameBufferVector.resize(machine().GetGraphicsAdapter().GetMonitorCount());
644}
645
646void UISession::prepareConnections()
647{
648 /* UICommon connections: */
649 connect(&uiCommon(), &UICommon::sigAskToDetachCOM, this, &UISession::sltDetachCOM);
650}
651
652void UISession::prepareSignalHandling()
653{
654#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
655 struct sigaction sa;
656 sa.sa_sigaction = &signalHandlerSIGUSR1;
657 sigemptyset(&sa.sa_mask);
658 sa.sa_flags = SA_RESTART | SA_SIGINFO;
659 sigaction(SIGUSR1, &sa, NULL);
660#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
661}
662
663void UISession::cleanupFramebuffers()
664{
665 /* Cleanup framebuffers finally: */
666 for (int i = m_frameBufferVector.size() - 1; i >= 0; --i)
667 {
668 UIFrameBuffer *pFrameBuffer = m_frameBufferVector[i];
669 if (pFrameBuffer)
670 {
671 /* Mark framebuffer as unused: */
672 pFrameBuffer->setMarkAsUnused(true);
673 /* Detach framebuffer from Display: */
674 pFrameBuffer->detach();
675 /* Delete framebuffer reference: */
676 delete pFrameBuffer;
677 }
678 }
679 m_frameBufferVector.clear();
680}
681
682void UISession::cleanupConsoleEventHandlers()
683{
684 /* Destroy console event-handler: */
685 delete m_pConsoleEventhandler;
686 m_pConsoleEventhandler = 0;
687}
688
689void UISession::cleanupNotificationCenter()
690{
691 UINotificationCenter::destroy();
692}
693
694void UISession::cleanupSession()
695{
696 /* Detach debugger: */
697 if (!m_comDebugger.isNull())
698 m_comDebugger.detach();
699
700 /* Detach keyboard: */
701 if (!m_comKeyboard.isNull())
702 m_comKeyboard.detach();
703
704 /* Detach mouse: */
705 if (!m_comMouse.isNull())
706 m_comMouse.detach();
707
708 /* Detach guest: */
709 if (!m_comGuest.isNull())
710 m_comGuest.detach();
711
712 /* Detach display: */
713 if (!m_comDisplay.isNull())
714 m_comDisplay.detach();
715
716 /* Detach console: */
717 if (!m_comConsole.isNull())
718 m_comConsole.detach();
719
720 /* Detach machine: */
721 if (!m_comMachine.isNull())
722 m_comMachine.detach();
723
724 /* Close session: */
725 if (!m_comSession.isNull() && uiCommon().isVBoxSVCAvailable())
726 {
727 m_comSession.UnlockMachine();
728 m_comSession.detach();
729 }
730}
731
732UIMachineLogic *UISession::machineLogic() const
733{
734 return uimachine() ? uimachine()->machineLogic() : 0;
735}
736
737UIMachineWindow *UISession::activeMachineWindow() const
738{
739 return machineLogic() ? machineLogic()->activeMachineWindow() : 0;
740}
741
742QWidget *UISession::mainMachineWindow() const
743{
744 return machineLogic() ? machineLogic()->mainMachineWindow() : 0;
745}
746
747bool UISession::preprocessInitialization()
748{
749#ifdef VBOX_WITH_NETFLT
750 /* Skip network interface name checks if VM in saved state: */
751 if (!isSaved())
752 {
753 /* Make sure all the attached and enabled network
754 * adapters are present on the host. This check makes sense
755 * in two cases only - when attachement type is Bridged Network
756 * or Host-only Interface. NOTE: Only currently enabled
757 * attachement type is checked (incorrect parameters check for
758 * currently disabled attachement types is skipped). */
759 QStringList failedInterfaceNames;
760 QStringList availableInterfaceNames;
761
762 /* Create host network interface names list: */
763 foreach (const CHostNetworkInterface &comNetIface, uiCommon().host().GetNetworkInterfaces())
764 {
765 availableInterfaceNames << comNetIface.GetName();
766 availableInterfaceNames << comNetIface.GetShortName();
767 }
768
769 /* Enumerate all the virtual network adapters: */
770 const ulong cCount = uiCommon().virtualBox().GetSystemProperties().GetMaxNetworkAdapters(machine().GetChipsetType());
771 for (ulong uAdapterIndex = 0; uAdapterIndex < cCount; ++uAdapterIndex)
772 {
773 CNetworkAdapter comNetworkAdapter = machine().GetNetworkAdapter(uAdapterIndex);
774 if (comNetworkAdapter.GetEnabled())
775 {
776 /* Get physical network interface name for
777 * currently enabled network attachement type: */
778 QString strInterfaceName;
779 switch (comNetworkAdapter.GetAttachmentType())
780 {
781 case KNetworkAttachmentType_Bridged:
782 strInterfaceName = comNetworkAdapter.GetBridgedInterface();
783 break;
784#ifndef VBOX_WITH_VMNET
785 case KNetworkAttachmentType_HostOnly:
786 strInterfaceName = comNetworkAdapter.GetHostOnlyInterface();
787 break;
788#endif /* !VBOX_WITH_VMNET */
789 default:
790 break;
791 }
792
793 if ( !strInterfaceName.isEmpty()
794 && !availableInterfaceNames.contains(strInterfaceName))
795 {
796 LogRel(("GUI: Invalid network interface found: %s\n", strInterfaceName.toUtf8().constData()));
797 failedInterfaceNames << QString("%1 (adapter %2)").arg(strInterfaceName).arg(uAdapterIndex + 1);
798 }
799 }
800 }
801
802 /* Check if non-existent interfaces found: */
803 if (!failedInterfaceNames.isEmpty())
804 {
805 if (msgCenter().warnAboutNetworkInterfaceNotFound(machineName(), failedInterfaceNames.join(", ")))
806 machineLogic()->openNetworkSettingsDialog();
807 else
808 {
809 LogRel(("GUI: Aborting startup due to preprocess initialization issue detected...\n"));
810 return false;
811 }
812 }
813 }
814#endif /* VBOX_WITH_NETFLT */
815
816 /* Check for USB enumeration warning. Don't return false even if we have a warning: */
817 CHost comHost = uiCommon().host();
818 if (comHost.GetUSBDevices().isEmpty() && comHost.isWarning())
819 {
820 /* Do not bitch if USB disabled: */
821 if (!machine().GetUSBControllers().isEmpty())
822 {
823 /* Do not bitch if there are no filters (check if enabled too?): */
824 if (!machine().GetUSBDeviceFilters().GetDeviceFilters().isEmpty())
825 UINotificationMessage::cannotEnumerateHostUSBDevices(comHost);
826 }
827 }
828
829 /* True by default: */
830 return true;
831}
832
833bool UISession::mountAdHocImage(KDeviceType enmDeviceType, UIMediumDeviceType enmMediumType, const QString &strMediumName)
834{
835 /* Get VBox: */
836 CVirtualBox comVBox = uiCommon().virtualBox();
837
838 /* Prepare medium to mount: */
839 UIMedium guiMedium;
840
841 /* The 'none' medium name means ejecting what ever is in the drive,
842 * in that case => leave the guiMedium variable null. */
843 if (strMediumName != "none")
844 {
845 /* Open the medium: */
846 const CMedium comMedium = comVBox.OpenMedium(strMediumName, enmDeviceType, KAccessMode_ReadWrite, false /* fForceNewUuid */);
847 if (!comVBox.isOk() || comMedium.isNull())
848 {
849 UINotificationMessage::cannotOpenMedium(comVBox, strMediumName);
850 return false;
851 }
852
853 /* Make sure medium ID is valid: */
854 const QUuid uMediumId = comMedium.GetId();
855 AssertReturn(!uMediumId.isNull(), false);
856
857 /* Try to find UIMedium among cached: */
858 guiMedium = uiCommon().medium(uMediumId);
859 if (guiMedium.isNull())
860 {
861 /* Cache new one if necessary: */
862 guiMedium = UIMedium(comMedium, enmMediumType, KMediumState_Created);
863 uiCommon().createMedium(guiMedium);
864 }
865 }
866
867 /* Search for a suitable storage slots: */
868 QList<ExactStorageSlot> aFreeStorageSlots;
869 QList<ExactStorageSlot> aBusyStorageSlots;
870 foreach (const CStorageController &comController, machine().GetStorageControllers())
871 {
872 foreach (const CMediumAttachment &comAttachment, machine().GetMediumAttachmentsOfController(comController.GetName()))
873 {
874 /* Look for an optical devices only: */
875 if (comAttachment.GetType() == enmDeviceType)
876 {
877 /* Append storage slot to corresponding list: */
878 if (comAttachment.GetMedium().isNull())
879 aFreeStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(),
880 comAttachment.GetPort(), comAttachment.GetDevice());
881 else
882 aBusyStorageSlots << ExactStorageSlot(comController.GetName(), comController.GetBus(),
883 comAttachment.GetPort(), comAttachment.GetDevice());
884 }
885 }
886 }
887
888 /* Make sure at least one storage slot found: */
889 QList<ExactStorageSlot> sStorageSlots = aFreeStorageSlots + aBusyStorageSlots;
890 if (sStorageSlots.isEmpty())
891 {
892 UINotificationMessage::cannotMountImage(machineName(), strMediumName);
893 return false;
894 }
895
896 /* Try to mount medium into first available storage slot: */
897 while (!sStorageSlots.isEmpty())
898 {
899 const ExactStorageSlot storageSlot = sStorageSlots.takeFirst();
900 machine().MountMedium(storageSlot.controller, storageSlot.port, storageSlot.device, guiMedium.medium(), false /* force */);
901 if (machine().isOk())
902 break;
903 }
904
905 /* Show error message if necessary: */
906 if (!machine().isOk())
907 {
908 msgCenter().cannotRemountMedium(machine(), guiMedium, true /* mount? */, false /* retry? */, activeMachineWindow());
909 return false;
910 }
911
912 /* Save machine settings: */
913 machine().SaveSettings();
914
915 /* Show error message if necessary: */
916 if (!machine().isOk())
917 {
918 UINotificationMessage::cannotSaveMachineSettings(machine());
919 return false;
920 }
921
922 /* True by default: */
923 return true;
924}
925
926void UISession::recacheMachineMedia()
927{
928 /* Compose a list of machine media: */
929 CMediumVector comMedia;
930
931 /* Enumerate all the controllers: */
932 foreach (const CStorageController &comController, machine().GetStorageControllers())
933 {
934 /* Enumerate all the attachments: */
935 foreach (const CMediumAttachment &comAttachment, machine().GetMediumAttachmentsOfController(comController.GetName()))
936 {
937 /* Skip unrelated device types: */
938 const KDeviceType enmDeviceType = comAttachment.GetType();
939 if ( enmDeviceType != KDeviceType_HardDisk
940 && enmDeviceType != KDeviceType_Floppy
941 && enmDeviceType != KDeviceType_DVD)
942 continue;
943 if ( comAttachment.GetIsEjected()
944 || comAttachment.GetMedium().isNull())
945 continue;
946 comMedia.append(comAttachment.GetMedium());
947 }
948 }
949
950 /* Start media enumeration: */
951 uiCommon().enumerateMedia(comMedia);
952}
953
954#ifdef VBOX_GUI_WITH_KEYS_RESET_HANDLER
955/**
956 * Custom signal handler. When switching VTs, we might not get release events
957 * for Ctrl-Alt and in case a savestate is performed on the new VT, the VM will
958 * be saved with modifier keys stuck. This is annoying enough for introducing
959 * this hack.
960 */
961/* static */
962static void signalHandlerSIGUSR1(int sig, siginfo_t * /* pInfo */, void * /*pSecret */)
963{
964 /* Only SIGUSR1 is interesting: */
965 if (sig == SIGUSR1)
966 if (gpMachine)
967 gpMachine->machineLogic()->keyboardHandler()->releaseAllPressedKeys();
968}
969#endif /* VBOX_GUI_WITH_KEYS_RESET_HANDLER */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette