VirtualBox

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

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

Merging r155576 and r155577 from gui4 branch: FE/Qt: Runtime UI: Reordering for UISession code; A bit of doxy fixes for UISession.

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